我正在尝试创建100%宽度和高度的多个div,但是仍然惨遭失败.例:
<html>
<body>
<div id="wrapper">
<div id="1">100% height & width, all you can see when opening this file!</div>
<div id="2">I'll be 100% when you've scrolled #1 out of the window!</div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这个解决方案的CSS是什么?我似乎无法让它工作.
解决方案首先重置默认值为margin
和padding
:
* {
margin:0;
padding:0;
}
Run Code Online (Sandbox Code Playgroud)
其次让您html
和body
为100%:
html, body {
height:100%;
}
Run Code Online (Sandbox Code Playgroud)
然后你的div维度:
#wrapper, #one, #two {
width:100%;
height:100%;
}
Run Code Online (Sandbox Code Playgroud)
您无法在第一个charachter上为id或class分配数值