I have a div-container
(colored blue) where I want to put 3 div-element
s (colored red).
div-element
s have to be vertically aligned (I just used margin-top: 10%;
for that) and first one has to be left, second centered and third right in the same line. To achieve that I have made 3 id
s #left
, #center
and #right
.
However it all gets messed up when I put those id
s in. First one is aligned allright, second one is centered but margin-top: 10%;
doesn't affect it anymore and the third one is on the right side but in the new line.
I have tried putting display: inline-block;
in my div-element
class. This aligns right element correctly but messes up the center one.
Why is this happening and how do I solve this?
It is quite obvious that I have tried How to align 3 divs (left/center/right) inside another div? since I have used exact same id
s, but the above mentioned solution doesn't work here and I have specifically asked why my margin-top: 10%;
in .div-element
doesn't affect center div
.div-container {
width: 50%;
height: 50%;
background-color: blue;
}
.div-element {
margin-top: 10%;
width: 20%;
height: 50%;
background-color: red;
}
#center {
margin: 0 auto;
}
#left {
float: left;
}
#right {
float: right;
}
<div class="div-container">
<div class="div-element" id="left">Left</div>
<div class="div-element" id="center">Center</div>
<div class="div-element" id="right">Right</div>
</div>