Sie müssen ein Elternteil mit einer relative position
können Sie innerhalb dieses Elternteils die absolute position
Ihrer divs
<div> <------Relative
<div/> <------Absolute
<div/> <------Absolute
<div/> <------Absolute
<div/>
Endgültiges Ergebnis:
https://codepen.io/hiteshsahu/pen/XWKYEYb?editors=0100
![enter image description here]()
<div class="container">
<div class="header">TOP: I am at Top & above of body container</div>
<div class="center">CENTER: I am at Top & in Center of body container</div>
<div class="footer">BOTTOM: I am at Bottom & above of body container</div>
</div>
HTML Body in voller Breite einstellen
html, body {
overflow: hidden;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
Danach können Sie ein div mit der relativen Position so einstellen, dass es die volle Breite und Höhe einnimmt
.container {
position: relative;
background-color: blue;
height: 100%;
width: 100%;
border:1px solid;
color: white;
background-image: url("https://images.pexels.com/photos/5591663/pexels-photo-5591663.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
background-color: #cccccc;
}
Innerhalb dieses div mit der relativen Position können Sie Ihr div mit absoluten Positionen setzen
On TOP über dem Container
.header {
position: absolute;
margin-top: -10px;
background-color: #d81b60 ;
left:0;
right:0;
margin:15px;
padding:10px;
font-size: large;
}
Unten über dem Behälter
.footer {
position: absolute;
background-color: #00bfa5;
left:0;
right:0;
bottom:0;
margin:15px;
padding:10px;
color: white;
font-size: large;
}
Im CENTER über dem Container
.center {
position: absolute;
background-color: #00bfa5;
left: 30%;
right: 30%;
bottom:30%;
top: 30%;
margin:10px;
padding:10px;
color: white;
font-size: large;
}