23

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
  • 24,944
  • 53
  • 156
  • 273

4 Answers4

59

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
  • 147,524
  • 33
  • 287
  • 271
  • 29
    +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
  • 8
    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,179
  • 21
  • 93
  • 129
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
  • 975
  • 9
  • 20
-2

It should be

ul li ul li a {

    text-decoration:none;
}​
Sirko
  • 69,531
  • 19
  • 142
  • 174
Ruchira Shree
  • 165
  • 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