I'm using a background image via CSS to style a few elements on my site. The problem I'm seeing in both Chrome and IE is that when the line-height of the line is smaller than the image is tall, the image gets cropped. Here's a fiddle that demonstrates the issue (again, view this with Chrome or IE to see the problem; Firefox renders things as I'd like), and here's the corresponding code from said fiddle:
HTML
<ul>
<li class="icon"><a href="#">Link 1</a></li>
<li class="icon"><a href="#">Link 2</a></li>
<li class="icon">No Link Here</li>
</ul>
CSS
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
ul li {
display: inline;
font-size: 13px;
margin: 0 1em 0 0;
padding: 0;
}
ul li.icon {
background: url(http://www.borngeek.com/images/2013/stack_overflow_ex_01.gif) no-repeat left center;
padding-left: 22px;
}
Note that in reality I don't hard-code the font-size in pixels; they just end up being rendered at 13 pixels high. I've hard-coded the value here to reproduce the problem.
None of the following seem to work:
- Setting
height
,line-height
, ormin-height
on the various elements (even parent elements) - Using the
overflow
value in various ways
Potential, problematic workarounds include:
- Changing the font size to something larger
- Using a nebulous
padding
value to prevent the image from being clipped - Using
display: inline-block
, which has its own set of issues - Using
float: left
, which also has some nits - Using the
<img>
element instead of CSS, which feels wrong in this case - Using the
background-size
CSS property I found in this answer, though support for this is spotty
Is there a cleaner way of handling this, or is one of the above workarounds my best bet? My only goal is for the parent element to be tall enough to render the entire 16x16 image.