Ha,
Today I found an elegant CSS way of aligning two DIVs vertically on their centers. After spending some search on Google and not finding a satisfactionary solution, I treid to create my own. Here it is:
<span> <div style="display:inline-block; vertical-align:middle"> RobAu's <br>Vertically aligned DIVS </div> <div style="display:inline-block; vertical-align:middle;width:100px;"> <div style="width:100px; height:150px; background-color:red"></div> <div style="width:100px; height:150px; background-color:blue"></div> </div> </span>
The span is used to have an normal line. The divs are converted to inline-blocks, like images. That way, they can be aligned in the middle.By simply putting two container DIVs in the span, they are alinged vertically, without giving any pre-set heights, percentages, positioning etc.
Feel free to use!
RobAu’s
Vertically aligned DIVS
Vertically aligned DIVS
Advertisement