I am trying to convert a design to HTML/CSS with equal amount of vertical space between the image and text, but unable to do so. The designer created this is 20px margin between the image, title, and desc, but due to the way CSS is processed with line height, the space is not the same between all these elements.
<div class="teaser-image">
<img src="teaser1.png">
</div>
<div class="teaser-title">At Your Service</div>
<div class="teaser-desc">
blah blah blah
</div>
.teaser-image, .teaser-title, .teaser-desc {
margin-bottom: 20px;
line-height: 21.6px;
}
.teaser-title {
font-family: "myriad-pro-condensed",sans-serif;
font-weight: 700;
font-size: 24px;
text-align: center;
}
.teaser-desc {
font-size: 16px;
font-family: "myriad-pro-condensed",sans-serif;
text-align: center;
}
You're on the right track. Set the
line-height
of the elements that need the 20px margin to1
. Setting to1
means that the line height will be equal to the current font size, as in, 100% the font size. Some examples:line-height: 1
font size = 20, line height = 20
line-height: 1.5
font size = 20, line height = 30 (20 x 1.5)
HTML
CSS
jsFiddle: http://jsfiddle.net/2ojvpp53/
For
.teaser-image
I set the font size to zero so that the descender height is removed from around the image.