27

I have this HTML:

<ul>
<li>
    <ul>
        <li>
            <a href="#"> <span> Test </span> Link </a>
        </li>
    </ul>
</li>
</ul>​

And this CSS:

ul li ul li span {

    text-decoration:none;
}​

Why would the span inside the anchor still have underline?

In other words: How would I get all the text underlined, except the SPAN. Thanks

Hommer Smith
  • 26,772
  • 56
  • 167
  • 296

4 Answers4

63

You need to target the anchor tag and not the span tag so use this

ul li ul li a {
    text-decoration:none;
}​

Reason: text-decoration: underline; is applied to <a> tag by default browser stylesheet, so if you want to over ride it or if you want that none of the <a> tags on your website should have an underline than simply use this

a {
   text-decoration: none;
}

Edit: As I read your comment if you want your text to be underline except the text within <span> than use this

Demo

ul li ul li a {
    text-decoration:underline;
}

ul li ul li a span {
    text-decoration:none;
    display: inline-block;
}
Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
  • 31
    +1 for 'display: inline-block' so that inner span tag no longer takes underline from parent block level element, thanks – Ben Sewards Nov 17 '14 at 22:19
  • 9
    Argh! Witchcraft! Can someone point at the spec that defines this behaviour? I would have tried a lot of random things before I tried changing the inner element's `display` property. – Neek Jun 19 '16 at 09:49
1

Make tat span in class as a

a is the tag which takes default underline since it is a link but not span. So whatever is inside the a tag takes the underline automatically.

ul li ul li a{
    text-decoration:none;
}​

DEMO

Sowmya
  • 26,684
  • 21
  • 96
  • 136
1

It should be

ul li ul li a {
text-decoration:none;
}
ul li ul li a:hover {
text-decoration:underline;
}

ul li ul li a span {
text-decoration:none;
display: inline-block;   
}

DEMO

Animesh
  • 1,005
  • 10
  • 20
-3

It should be

ul li ul li a {

    text-decoration:none;
}​
Sirko
  • 72,589
  • 19
  • 149
  • 183
Ruchira Shree
  • 163
  • 10
  • Can you please tell me what it was previuosly , cant see why you have edited , as per my remeberance it was this only ul li ul li a { text-decoration:none; }​ – Ruchira Shree Dec 13 '12 at 11:06
  • @Ruchira.. you can click on the `edited 3hrs` link above to view the previous edits. – Kent Pawar Dec 13 '12 at 13:55