2
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.parent {
height: 100vh;
overflow: auto;
}
.first {
height: 100vh;
}
.second {
height: 100vh;
}
</style>
</head>
<body>
<div class="parent">
<div class="first">
<h1>haha</h1>
</div>
<div class="second">
<h1>haha</h1>
</div>
</div>
</body>
</html>
演示:http://codepen.io/anon/pen/zxKmyq什麼導致兩個滾動條在這裏?
這個代碼將會給在左邊的兩個滾動條。
但是,如果我們的代碼更改爲
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
* { <!-- this is the only modification I made compared to the first code -->
margin:0;
padding:0;
}
.parent {
height: 100vh;
overflow: auto;
}
.first {
height: 100vh;
}
.second {
height: 100vh;
}
</style>
</head>
<body>
<div class="parent">
<div class="first">
<h1>haha</h1>
</div>
<div class="second">
<h1>haha</h1>
</div>
</div>
</body>
</html>
演示:http://codepen.io/anon/pen/gbwBQK
然後有將只有一個滾動條,這是可取的。
但我不知道這是如何工作的,即爲什麼這個簡單的修改會改變滾動條。
那麼你的問題是什麼?請明確點。 – simeg