我在一個頁面上工作,它被分成4個div,它們的合計高度爲100%。容器也使用100%的高度,並且沒有定義邊距或填充。 那麼,爲什麼我的網頁顯示滾動條?CSS:爲什麼我有一個100%高度的滾動條?
CSS:
#container {
min-height:100%;
}
#first_div {
height:5.5%;
width:100%;
text-align:center;
border-bottom: 1px solid black;
}
#second_div {
height:31.5%;
width:100%;
border-bottom: 1px solid black;
}
#third_div {
width:100%;
height:31.5%;
border-bottom: 1px solid black;
}
#fourth_div {
height:31.5%;
width:100%;
}
body, html, #container {
height: 100%;
background-color: #f4f5f2;
}
body {
position: relative;
background: transparent;
overflow-x: hidden;
color: black;
}
h1 {
font-family: Helvetica Neue,Helvetica,Arial,sans-serif;
font-size: 28px;
font-style: normal;
font-variant: normal;
font-weight: 500;
line-height: 30px;
}
h3 {
font-family: Helvetica Neue,Helvetica,Arial,sans-serif;
font-size: 14px;
font-style: normal;
font-variant: normal;
font-weight: 500;
line-height: 15.4px;
}
p {
font-family: Helvetica Neue,Helvetica,Arial,sans-serif;
font-size: 14px;
font-style: normal;
font-variant: normal;
font-weight: 400;
line-height: 19.99px;
padding-left:1em
}
blockquote {
font-family: Helvetica Neue,Helvetica,Arial,sans-serif;
font-size: 21px;
font-style: normal;
font-variant: normal;
font-weight: 400;
line-height: 29.99px;
}
pre {
font-family: Helvetica Neue,Helvetica,Arial,sans-serif;
font-size: 13px;
font-style: normal;
font-variant: normal;
font-weight: 400;
line-height: 18.57px;
}
.background-1, .background-2 {
position: absolute;
z-index: -1;
width: 100%;
height: 100%;
background: transparent;
}
HTML:
<div class="background-1">
<div id="container">
<div id="first_div" ><h1>Headline1</h1></div>
<div id="second_div"><p><b>Text:</b> Text</p></div>
<div id="third_div"><p><b>Room</b> Text</p></div>
<div id="fourth_div"><p><b>Start:</b> 10:45 Uhr</p></div>
</div></div>
<div class="background-2">
<div id="container">
<div id="first_div" ><h1>Headline2</h1></div>
<div id="second_div"><p><b>Text:</b> Text</p></div>
<div id="third_div"><p><b>Room</b> Text</p></div>
<div id="fourth_div"><p><b>Start:</b> 10:45 Uhr</p></div>
</div></div>
注意這裏是因爲這個JavaScript的不能同時顯示只有一個容器,:
$(document).ready(function(){
var bgArr = ["image.jpg","image.jpg", "image.jpg"];
var i = 0;
var $bg1 = $('.background-1').css('background-image', 'url('+bgArr[0]+')').css('left', '0%');
var $bg2 = $('.background-2').css('background-image', 'url('+bgArr[1]+')').css('left', '-100%');
var bgSlide = function($bg) {
$bg.animate({ left: '+=100%' }, 600, function(){
if(parseInt($bg.css('left')) > 0) {
$bg.css('left', '-100%');
(i < bgArr.length-1) ? i++ : i=0;
$bg.css("background-image", "url("+bgArr[i]+")");
}
});
}
setInterval(function() {
bgSlide($bg1);
bgSlide($bg2);
}, 10000);
});
這裏是jsfiddle。
:100 ''容器'的%'' –
否則內容不會延伸到整個頁面,四個不同的div實際上不會是p的5%和31.5%年齡,只有容器 – Fynn