I have a class that has both a background image and text. I'm trying to figure out a way to manipulate the space above the Text Only, using the "margin" tag will change the position of the entire thing (image + text). I need to control the text only.
text-indent gives me some control over the horizontal spacing, but I need something to have more control over the space above and below the text only if such thing exists.
Here's the CSS class:
.contactb { float:left; margin:0 5px 0 0; padding:0 0; background:url(images/contact_b.png) top no-repeat; display:block; width:108px; height:57px; font-family: 'hand-webfont'; color:black; font-size:17px; }
Here's the HTML code:
<li><a href="contact.html" class="contactb">Contact</a></li>
Creating extra spaces before or after text To create extra spaces before, after, or in-between your text, use the (non-breaking space) extended HTML character.
Margin is providing space beyond the element's box and therefore won't be colored - it's simply space. Padding on the other hand provides space around the inside of the element's box and is colored and affected by other styles.
You're simply looking for 'padding':
.myClass {
padding-top: 10px
padding-bottom: 10px;
}
Here's a working example of what I think you're trying to do: http://jsfiddle.net/yhV78/
The trick:
The trick is to combine padding with background-origin... Though, it is supported only in CSS 3 capable browsers (not in older Internet Explorer versions: before Internet Explorer 9)
This
background-origin:border-box;
plus appropriate padding works fine for me... (The default value for background-origin is padding-box, which is the reason, padding alone doesn't work for you...)
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