Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove underline from span inside anchor

Tags:

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

like image 387
Hommer Smith Avatar asked Dec 13 '12 09:12

Hommer Smith


People also ask

How do I hide the underline in an anchor tag?

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.

How do I remove the underline from a link tag in react?

Use inline styles to remove the underline of a Link in React, e.g. <Link style={{textDecoration: 'none'}} to="/"> . When the text decoration property is set to none , the underline of the link is removed.

Can we use span inside anchor tag?

It is perfectly valid (at least by HTML 4.01 and XHTML 1.0 standards) to nest either a <span> inside an <a> or an <a> inside a <span> . i.e. with both HTML 4.01 and XHTML 1.0 doctypes, and both passed validation successfully! Only thing to be aware of is to ensure that you close the tags in the correct order.


1 Answers

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; } 
like image 185
Mr. Alien Avatar answered Oct 20 '22 05:10

Mr. Alien