Forum Moderators: not2easy
In other words, the text within a link and the horizontal space that is between it and the underline appears to be 1px; how can I adjust it to more than 1px?
For reference, anyone with a customized my_yahoo news page can see what I am talking about where the news links appear to have a 2px seperator between the links and the underlines.
I have tried line-height, padding, margin, etc. but they all adjust the outer perimeter and not the distnce between the wording and underline.
I believe the distance between text and underline is a function of the font baseline. Consider this from the W3 specs for the text-decorationproperty:
In determining the position of and thickness of text decoration lines, user agents may consider the font sizes of and dominant baselines of descendants...
I do not believe there is a way to alter font baselines using CSS.
where the news links appear to have a 2px seperator between the links and the underlines.
Under section '2.' the first sample with green text, blue text, red text, etc. has a larger spacing between the text and underline (2px?).
I viewed the source and it looks like nothing more than standard CSS 'text-decoration: underline', which leads me to believe the distance is either a product of my browser (ie6) or the type of font used.
Does anyone else see the space difference with different browsers? Do different text fonts generate different spacing between underlines?
This leads me to believe that this is all merely an issue of font baselines, which is altered as text is made bold, or larger, ect.
If you really want control over the gap, I'd use claus' solution. You could just as easily style border-bottom to vanish on rollover like you can text-decoration (or change color, or do nothing at all), and it will give you control over the distance to the line...
<p>This is your text with a <a href="#">link</a>.</p>
a {
text-decoration: none;
border-bottom: 1px solid #fff;
padding-bottom: 2px;
}
a:hover{
border-bottom:0;
}
Works like a charm. (Nice one, claus.)
If you really want control over the gap, I'd use claus' solution. You could just as easily style border-bottom to vanish on rollover like you can text-decoration (or change color, or do nothing at all), and it will give you control over the distance to the line...<p>This is your text with a <a href="#">link</a>.</p>
a {
text-decoration: none;
border-bottom: 1px solid #fff;
padding-bottom: 2px;
}
a:hover{
border-bottom:0;
}Works like a charm. (Nice one, claus.)
This does work well, but I should point out a potential problem with it; if you have linked images, they get the underline too!
The only way I can think of to turn this behaviour off is to put every image inside another element, and adjust the stylesheet accordingly:
HTML:
<div class="imageWrap">
<a href="img/bigExample.gif" title="Click to enlarge this image">
<img src="img/example.gif" width="50" height="50" alt="example image">
</a>
</div>
div.imageWrap a {
border-style:none;
}
The problem is that the link is what gets the underline so that, unless there is a way of specifying the borders of elements that have certain child elements, there is no way to turn it off except by creating a special context for un-underlined links.
-B
a img {
border-bottom:0;
}
Nope. That won't help at all - that's exactly what my post was about.
That rule keeps an image inside a link from having a bottom border. The problem we're talking about is when a link is styled to have a bottom-border, and then an image is placed inside a link. The problem is that, whatever you define for the image, the link still has that bottom-border - unless you try one of my or CEM's solutions.
-B