我想创建一个将具有100%高度的DIV。但这不起作用。我还试图在Stackoverflow上搜索一个解决方案,但不幸的是,它们都没有起作用。我认为,通过将100%放在HTML和身体上可以使其起作用,但事实并非如此。这是我的标记,然后是我的CSS。我正在使用ASP.NET VS2010。我是设计网页的新手。
<div class="hundredpercentdiv">
<p>This content should have 100% height</p>
</div>
html,body{
height:100%;
}
body{
background:#fff;
color:#333;
}
p{
font-size:2em;
text-align:center;
}
.hundredpercentdiv{
height:100%;
background-color:Green;
}
更改body
和p
标签的默认样式,即它们的默认margin
到0px
,
html,body{
height:100%;
}
body{
background:#fff;
color:#333;
margin:0; /*Add this*/
}
p{
font-size:2em;
text-align:center;
margin:0; /*Add this*/
}
.hundredpercentdiv{
height:100%;
background-color:Green;
}
<div class="hundredpercentdiv">
<p>This content should takes up 100% of the viewport</p>
</div>