Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selectively stopping text-decoration: underline on children of a link tag

Tags:

html

css

Does anybody know if it's possible to prevent underlining on the child of an tag, while underlining the rest of the tag's contents?

Here's an example - you can see this working on JSFiddle. I've tried everything I can think of, but the text underlining continues to be applied to all the text inside the link. I'm viewing on Chrome, but I'm sure this applies to all browsers.

a {
    font-size: 32px;           
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

a div {
    color: pink;
}

a:hover div,
a:active div,
a:focus div {
    text-decoration: none !important;
}​

<a href="http://news.bbc.co.uk">
<div class="inner">I don't want this bit underlined on hover. What's the big deal?</div>
This bit should be underlined on hover. Underlining here is fine. I have no objections to underlinining in this bit.
</a>​
like image 949
And Finally Avatar asked Nov 22 '12 09:11

And Finally


People also ask

Can you use text-decoration to remove the underline from links?

To remove the underline from links, you can use the CSS text-decoration property.

How do you stop text underline in HTML?

In HTML, text-decoration none (text-decoration:none;) removes all the Text element stylings like Underlines. So if you want to remove Underlines from Links you can use this text-decoration:none; CSS property to get rid of that underline from the texts/links.

How do I remove the underline from a link tag?

To remove underline from a link in HTML, use the CSS property text-decoration. Use it with the style attribute. The style attribute specifies an inline style for an element. Use the style attribute with the CSS property text-decoration to remove underline from a link in HTML.


1 Answers

Read this similar answer and its links for more information: Remove :hover on :after elemets

http://jsfiddle.net/thirtydot/ygXy6/4/

CSS:

a {
    font-size: 32px;           
    text-decoration: none;
}

a:hover span {
    text-decoration: underline;
}

HTML:

<a href="http://news.bbc.co.uk">
    <div class="inner">I don't want this bit underlined on hover. What's the big deal?</div>
    <span>This bit should be underlined on hover. Underlining here is fine. I have no objections to underlinining in this bit.</span>
</a>​
like image 118
thirtydot Avatar answered Sep 28 '22 23:09

thirtydot