Vertically Align Arbitrary Length String Relative To Image
Posted December 7th, 2010 in Programming / Comments OffTags: CSS
When coding web pages, a common problem is aligning (link) text vertically, often in relation to an icon. This is easily accomplished by setting height and line-height equal and by adding padding for the icon which is set as the background-image centered vertically.
<style>
a {
background:url('16x16icon.png') no-repeat left center;
display:block;
height:16px;
line-height:16px;
padding-left:20px;
}
</style>
<a href="#">Link Text</a>
But what if the link text needs to span more than one line for the given width? What if the icon is taller than the text height?