我使用JQuery使DIV具有与宽度相同的高度并作出响应更新。DIV匹配其他div与不同长宽比的高度与JQuery响应式
我还需要制作另一个DIV(具有不同的宽高比)与方格保持相同的高度。
调整浏览器窗口,即使黑DIV应匹配的红色和白色的div的高度。
function update() {
$(".match").each(function() {
var height = $(this).width();
console.log(height);
$(this).css('height', height + 'px');
});
}
update();
$(window).resize(function() {
update();
});
.main {
width: 100%;
max-width: 1200px;
margin: 0 auto;
height: 2000px;
background-color: #333333;
}
.square {
width: 10%;
background-color: #ffffff;
float: left;
}
.oblong {
width: 40%;
float: left;
max-height: 150px;
background-color: #000000;
}
.color {
background-color: red !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<div class="main">
<div class="oblong match"></div>
<div class="square match"></div>
<div class="square match color"></div>
<div class="square match"></div>
<div class="square match color"></div>
<div class="square match"></div>
<div class="square match color"></div>
</div>
所以你要输出 – Bhargav
什么?如果我理解你的权利,你要到div“椭圆形匹配” rezise像其他尺寸相同,当你reszise窗口? – reporter