I have 3 images vertically aligned in fixed height div. How can I make sure that the top and bottom padding between them remains even when an image is added or deleted.
Say the Div height is 100px and the image height is 20px. So 3 images with 20px would sum up to 60px. The remaining 40px should evenly get distributed as padding between the images.
Similarly when another image is added, the remaining 20px should be total padding between all images.
The property : vertical-align: middle is not working here.
The vertical-align property can be used in two contexts: To vertically align an inline element's box inside its containing line box. For example, it could be used to vertically position an image in a line of text. To vertically align the content of a cell in a table.
You want to:
display:table
with a fixed height,<img>
in element with display:table-row
and display:table-cell
display:block
vertical-align:middle
This will cause the space to be evenly distributed vertically.
Code:
<ul id="img-list">
<li><span><img src="http://phrogz.net/tmp/gkhead.jpg"></span></li>
<li><span><img src="http://phrogz.net/tmp/gkhead.jpg"></span></li>
<li><span><img src="http://phrogz.net/tmp/gkhead.jpg"></span></li>
</ul>
#img-list { display:table; height:100px }
#img-list img { height:20px; display:block }
#img-list li { display:table-row }
#img-list li span { display:table-cell; vertical-align:middle; background:red }
#img-list li:first-child,
#img-list li:last-child { height:20px }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With