I set a left floating div (navigation) below an absolute positioned div (header). Aside of the left floated div I have another div (article) with a margin a little bigger than the width of the floating div (just usual for a two column layout). Both, navigation and article gets a top-margin of 4em (header has height of 3em) The navigation div is positioned with an extra margin of 4em. I can solve this, but my question is: Why the extra margin. If I omit the absolute positioning of the header, it looks like I would expect: header - margin - navigation and article on one line. code:
* {
box-sizing: border-box;
}
body { /*schalte voreinstellung Browser aus */
margin: 0px;
padding: 0px;
}
header {
position: absolute;
top: 1px;
left: 0px;
height: 3em;
width: 100%;
padding: 10px;
border: 1px solid blue;
border-radius: 0.5em;
background-color: silver;
}
nav {
float: left;
width: 17em; /*breite relativ zum Buchstaben "m" in der aktuellen Schriftgroesse */
border: 1px dashed red; /*Rand und padding jedoch in pixel */
margin-top: 4em;
padding: 5px;
}
article {
margin: 4em 1em 0em 18em; /* top right bottom left */
padding: 0px 10px;
border: 1px dashed red;
min-width: 15em;
}
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Layout</title>
</head>
<body>
<header>
headline - position fixed würde sie fest halten
</header>
<nav>
<h2> Navigation </h2>
<ul>
<li> hier die links </li>
</ul>
</nav>
<article>
<h1>CSS-basierte Layouts</h1>
<h2>2 Spalten</h2>
die ziemlich leer sind
</article>
</body>
</html>