unexpected layout with DOCTYPE
This question already has an answer here:
The <!DOCTYPE html>
line has nothing to do with it.
To get scrollbars only on your main
element, you need to set height: 100%
for its parent elements body
and html
:
<!DOCTYPE html>
<html lang="en" style="height: 100%;">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0">
<title>Off Track</title>
</head>
<body style="margin: 0px; padding:0px; height: 100%;">
<header style="background:green; width:100%; height: 50px;">
</header>
<main style="background:red; width:100%; height:calc(100% - 70px); overflow-y: auto">
bla bla <br> bla bla <br> bla bla <br> bla bla <br> bla bla <br>
bla bla <br> bla bla <br> bla bla <br> bla bla <br> bla bla <br>
bla bla <br> bla bla <br> bla bla <br> bla bla <br> bla bla <br>
bla bla <br> bla bla <br> bla bla <br> bla bla <br> bla bla <br>
bla bla <br> bla bla <br> bla bla <br> bla bla <br> bla bla <br>
bla bla <br> bla bla <br> bla bla <br> bla bla <br> bla bla <br>
bla bla <br> bla bla <br> bla bla <br> bla bla <br> bla bla <br>
bla bla <br> bla bla <br> bla bla <br> bla bla <br> bla bla <br>
bla bla <br> bla bla <br> bla bla <br> bla bla <br> bla bla <br>
</main>
<footer style="background: yellow; width:100%; height:20px;">
</footer>
</body>
</html>
链接地址: http://www.djcxy.com/p/89398.html
下一篇: 意想不到的布局与DOCTYPE