0

我正在创建一个移动网站,并想将我的一些元素的高度设置为宽度的倍数,如果我说得不够清楚,对不起,这里是我想要做的一个例子。

#myDiv{
width : 40%;
height : width * 1.4;
}

我最初只是要将高度设置为 +-50%,但后来我意识到我会根据手机的屏幕尺寸放松纵横比。

4

1 回答 1

2

@cinnanon is right, this can't be done with CSS alone.

You could use jQuery (javascript), although this is probably not the best practice for building a responsive site:

var adjustHeight = 1.4;

$(document).ready(function () {
    $('div').css('height', ($('div').width() * adjustHeight));
});

$(window).resize(function () {
    $('div').css('height', ($('div').width() * adjustHeight));
}); 

http://jsfiddle.net/philsinatra/pqz59/

于 2013-06-13T15:03:04.107 回答