views:

245

answers:

3

I have some inline links with icon showing on the left (padding + bacground), but when the font is too small, the image doesn't fit in line height and gets cropped on top and bottom. Is there any way to prevent it from happening, without use of javascript? I don't want to set font size in px..

Some min-line-height set to non-relative value (image's height) would be ideal.

A: 

When your text is set within tags, say <span class="with_image_background">Text</span> you should be able to set the min-height of that span to a fixed value.

I am currently not able to test it though, as I'm not sure if inline-elements support min-height. Just give it a try and comment on the results.

ApoY2k
you can't set height (and min-height) on inline elements
saji
Okay, thanks for the hint - as I said, I don't have the possibility to try it out. In that case, I'll try to think of an other answer and edit mine.
ApoY2k
+1  A: 

When dealing with inline elements inside block elements, you don't have a lot of options for changing the size of their bounding box. min-height doesn't work on inline elements, and line-height won't have any effect.

Setting an appropriate padding might be a reasonable option, but you'll likely run into issues with the element's background overlapping other elements inside the containing block.

As a quick demo, try this:

<!DOCTYPE html>
<html>
    <head>
        <title>Demo</title>
        <style type="text/css">
            span {
                background: #0F0;
                padding:    0.5em 0;
            }
        </style>
    </head>
    <body>
        <p>This is some demo text.  Look at how <span>texty</span> it is.</p>
    </body>
</html>

You'll see that the background of the texty span expands vertically, but it'll overlap text on preceding and following lines. You could set the element's display property to inline-block in modern browsers to avoid this issue, but then you'll have inconsistent line spacing, which would almost certainly be distracting if it's inside a block of text.

I think your best option, like it or not, is simply to ensure that the image you'd like to apply to your links fits the text you'll be displaying.

Mike West
thanks a lot for that {:
saji
A: 

you may be able to use display:inline-block to allow the min-height as inline tags are a little restricted

andy-score