[英]Setting div's or sections to the size of the viewport
我在使用CSS / JavaScript執行此操作時遇到麻煩,我想將頁面的多個部分設置為瀏覽器窗口的確切高度和寬度。 如果他們像調整部分一樣調整瀏覽器窗口ID。 我正在尋找的是與此類似的效果
使用Javascript
$(document).ready(function() {
$('section').css('minHeight',$(window).height() + 'px');
});
CSS
section{width:100%;}
嘗試以下代碼:
jQuery的
$(window).resize(function() {
calculateSectionContainerHeight();
});
$(document).ready(function (){
calculateSectionContainerHeight();
});
// function to calculate section container height
function calculateSectionContainerHeight() {
var docHeight = $(document).height();
// setting the section container height.
$('#section-container').height(sectionHeight + "px");
}
CSS
#section-container {
width:100%;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.