I have a super simple page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="@Url.Content("~/ui/all.min.css")" type="text/css" />
</head>
<body>
<div class="header">
</div>
</body>
</html>
and the css:
.header
{
height:70%;
width:100%;
background:#990663;
}
body
{
margin:0px;
padding: 0px;
height:100%;
width:100%;
}
*
{
margin: 0px auto;
}
I want the div height to be 70% of screen. How can I achieve that? If I put 400px in height, it works. So why not 70%? Any ideas how to achieve this?
You just need to update
htmlto have a 100% height (as well asbody):(JSFiddle)
This is because
100%is always relative to the parent container (forbodythat’shtml).One helpful post on the topic is here. FTA: