Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

text-decoration:none doesn't remove text decoration

Consider the following code HTML:

<span class='c1'>Home<sup id='id1'>[2]</sup></span>

CSS:

.c1
{
    text-decoration:underline;
}
#id1
{
    text-decoration:none !important;
}

Now I expected Home to have an underline while the superscript [2] doesn't have the underline. But it so happens that the superscript is also getting the underline. What am i missing here??

http://jsfiddle.net/sasidhar/DTpEa/

like image 947
sasidhar Avatar asked Aug 18 '11 20:08

sasidhar


People also ask

How do I get rid of text decor?

By setting the text-decoration to none to remove the underline from anchor tag. Syntax: text-decoration: none; Example 1: This example sets the text-decoration property to none.

What will happen to a text when you set its decoration to none?

The style rule em { text-decoration: none; } would not cause any change; the entire paragraph would still be underlined. However, the rule em { text-decoration: overline; } would cause a second decoration to appear on "some emphasized words".

Can text-decoration be transitioned?

Here I just created a very basic example to illustrate what I was seeing. As it turns out, text-decoration is not one of the properties that can be animated at all, including transitions. So, I went another route. By applying a bottom border instead, I can simulate an underline, and I can animate it.


2 Answers

If you think about it, the sup isn't underlined. but the span still is. Since the sup is inside the span, you see the underline which appears to be sup's underline.

Consider this demo: http://jsfiddle.net/mrchief/DTpEa/24/

You'll see that the id1 css does take precedence, but you still see the underline which is that of the span.

To solve it, have the sup outside of the span:

<span class='c1'>Home</span><sup id='id1'>[2]</sup>
like image 110
Mrchief Avatar answered Oct 07 '22 14:10

Mrchief


Here is a correct variant http://jsfiddle.net/rTUDN/

<div>
    <span class='c1'>Home</span>
    <sup id='id1'>[2]</sup>
</div>

.c1
{
    text-decoration:underline;
}
#id1
{
    text-decoration:none;
}
like image 38
Arsen K. Avatar answered Oct 07 '22 14:10

Arsen K.