我使用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