【发布时间】:2013-11-02 22:15:01
【问题描述】:
我有类似下面的内容:
<div id="left">
left
</div>
<div id="right">
right
</div>
带有 .css 属性:
#left {
width: 60%;
float: left
min-height: ###
max-height: 1000px;
}
#right {
width: 40%;
float: right;
min-height: ###
max-height: 1000px;
}
注意### 的<div> CSS min-height 属性。我想要类似下面的东西(一些伪 JS):
var leftheight = document.getElementById(left);
var rightheight = document.getElementById(right);
if (leftheight.currentHeight > rightheight.currentHeight) {
rightheight.style.min-height = leftheight.currentHeight;
} else if (rightheight.currentHeight > leftheight.currentHeight) {
leftheight.style.min-height = rightheight.currentHeight;
}
基本上我想要:
if (current height of left > current height of right) {
min-height of right = current height of left
} else if (current height of right > current height of left) {
min-height of left = current height of right
}
//ie. both left and right have the same min-heights, whichever is larger
我的 Javascript 是错误的,这是我刚刚学习的东西。有什么方法可以让我得到我想要的结果吗?
【问题讨论】:
-
@RoryMcCrossan,我之前看过这个问题,共识似乎是使用填充/边距解决方案,我认为它缺乏技巧并且是一个“便宜的出路”;我希望用 JS 或 jQuery 来解决它。
-
正如我在回答中所说,CSS 正是应该用于布局。 Javascript 应该永远用于那个。/
标签: javascript jquery css