【发布时间】:2013-06-17 04:10:16
【问题描述】:
当高度是父 div 的百分比时,是否可以使用 css 或 js 设置元素的宽度以匹配它的高度。如果调整浏览器窗口的大小,子 div 也需要更改大小。
示例
body, html {height: 100%}
.parent {height: 100%; width: 960px;}
.child {
height: 50%;
width: same as height; /* but not 50% of 960px, so that the child div is square*/
}
我正在尝试实现这样的目标,但要实现宽度而不是高度。 Height equal to dynamic width (CSS fluid layout)
提前致谢:-)
【问题讨论】:
-
Javascript,我的朋友。
标签: javascript css dynamic height width