So I am just starting to learn some basic CSS and now I have come across some behavior I don't understand. I have a <div>
inside an <article>
and the <div>
s height is set to 100%. Now if all the parents parents of the <div>
have their height specified then the height is equal to the parents height, however when it is not the case then <div>
s height is smaller.
Here is a simple example when not all heights are specified:
html {
height: 100%;
}
article {
background-color: red;
height: 100%;
}
#side-nav {
background-color: blue;
float: left;
min-width: 10%;
height: 100%;
padding: auto;
margin: 0;
}
#main-content {
margin-left: 10%;
width: 90%;
}
<!DOCTYPE html>
<html>
<head>
<title>some title</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav id="top-nav">
<div id="main-nav-bar">
<a class="nav-bar-opt">opt1</a>
<a class="nav-bar-opt">opt2</a>
<a class="nav-bar-opt">opt3</a>
</div>
</nav>
<article id="article">
<div id="side-nav">
<ul>
<li><a class="art-link">bullet</a></li>
<li><a class="art-link">point</a></li>
<li><a class="art-link">list</a></li>
</ul>
</div>
<div id="main-content">
<h1>
title
</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris condimentum sodales nulla a imperdiet. Ut interdum rhoncus luctus. Fusce porttitor eu nulla eu consectetur. Vivamus et pretium dolor, quis lobortis mauris. Quisque dignissim auctor nisl placerat placerat. Vivamus ultrices leo nec tincidunt ornare. Nulla accumsan euismod metus nec congue.
</p>
<h3>
title
</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris condimentum sodales nulla a imperdiet. Ut interdum rhoncus luctus. Fusce porttitor eu nulla eu consectetur. Vivamus et pretium dolor, quis lobortis mauris. Quisque dignissim auctor nisl placerat placerat. Vivamus ultrices leo nec tincidunt ornare. Nulla accumsan euismod metus nec congue.
</p>
<ul>
<li>another</li>
<li>bullet</li>
<li>point</li>
<li>list</li>
</ul>
</div>
</article>
</body>
</html>
note that the <div>
(colored in blue) is smaller than the direct parent <article>
(colored in red).
So now my question is if there is a reason for this behavior and if there is some workaround to avoid specifying all heights?