强制两个<div>到相同的大小,但减去一个具有X像素的div

时间:2017-01-29 20:31:03

标签: javascript jquery html

我使用Javascript:

将两个<div>带到同一高度
var tallness = $("#first").height();
$("#second").height(tallness);

但是如何管理<div> id="second"id="first"短20px

提前致谢!

1 个答案:

答案 0 :(得分:2)

您只需substract来自height值的$("#second").height(tallness-20);

var tallness = $("#first").height();
$("#second").height(tallness-20);
console.log("First div height: "+ $("#first").height());
console.log("Second div height: "+ $("#second").height());

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="first">
  first<BR>
  first<BR>
  first
</div>
<div id="second">
  second
  second
  second
</div>
{{1}}