html - How do I get these divs stack on top of each other right in the center of the page? -
i still don't understand how center divs. in fiddle, can see have centered divs they're overlapping. i've set both display inline-block thinking solve it, didn't anything.
https://jsfiddle.net/fyu1sup0/1/
html, body { font-family:; margin:0 auto; text-transform: lowercase; font-family: europa; letter-spacing: 0.5px; } .container { padding:0; margin:0 auto; } .top { background-color: blue; position: absolute; width: 300px; height: 200px; z-index: 15; top: 50%; left: 50%; margin: -100px 0 0 -150px; display:inline-block; } .top h1 { width:100%; font-size:50px; color:#2ccdad; } .bottom { position: absolute; width: 300px; height: 200px; z-index: 15; top: 50%; left: 50%; margin: -100px 0 0 -150px; display:inline-block; } .bottom h1 { font-size:40px; color:black; width:100%; }
you need use wrapper element. use transform: translatey(-50%)
adjust position of wrapper center of page.
see https://jsfiddle.net/labo59nx/
html, body { font-family:; margin:0 auto; text-transform: lowercase; font-family: europa; letter-spacing: 0.5px; } .wrapper { position: absolute; width:300px; top: 50%; left: 50%; margin: 0 0 0 -150px; transform: translatey(-50%); } .container { padding:0; margin:0 auto; } .top { background-color: blue; width: 300px; height: 200px; z-index: 15; display:inline-block; } .top h1 { width:100%; font-size:50px; color:#2ccdad; } .bottom { background-color:red; width: 300px; height: 200px; z-index: 15; display:inline-block; } .bottom h1 { font-size:40px; color:black; width:100%; }
<body> <div class="wrapper"> <div class = "top"> <div class="container"> <h1>header</h1> </div> </div> <div class = "bottom"> <div class="container"> <h1>text</h1> </div> </div> </div> </body>
Comments
Post a Comment