To continue my question Vertically center align divs with unknown height
I have such code:
https://jsfiddle.net/yyjde1gb/
#test {
background: yellow;
display: flex;
align-items: center;
}
#block1 {
background-color: grey;
}
#block2 {
background-color: green;
margin-left: auto;
}
<div id="test">
<div id="block1">
<div>test</div>
<div>test</div>
<div>test</div>
<div>test</div>
<div>test</div>
<div>test</div>
<div>test</div>
<div>test</div>
<div>test</div>
<div>test</div>
</div>
<div id="block2">
sample
</div>
</div>
It uses flex.
The question is: is it possible to get the same result without flex (and without JavaScript surely)?
IMPORTANT: It is forbidden to hard-code any heights or widths in pixels, ems, percent, ... (which makes the difficulty for this question). All the heights and widths are implicitely formed only by the contained text. That's an adaptive footer prototype.
First thing that comes to mind is to use floats - but it is impossible because of the vertical-align: middle
of the "block2" div (floats are vertical-align: top
only) - see details in Vertically center align divs with unknown height .
EDIT1: The "test" div is supposed to span to all the width of the page since it is a footer.
EDIT2: The proposed solution should support the oldest browsers possible.
UPDATE1: The best answer is by @Muhammad Usman. The pseudo-element :after
is supported in older browsers that transform
proposed by @Nenad Vracar's answer. Thank you everybody!
UPDATE2: In the @Muhammad Usman's answer it may be necessary to add line-height
property - if it is declared in some parent block (thus affecting our footer). I had to add line-height: 0;
to the zero-sized font block and line-height: 16px;
to the block with 16px font size.