简体   繁体   中英

Can a span be nested in a link in HTML5?

I've often placed <span> elements inside if a <a> element in XHTML transitional.

I'm writing against HTML5 right now and Visual studio 2010 tells me that it's illegal in HTML5.

Is this correct? If so, what would be the best way to style a portion of the text inside of a link an alternate color?

According to the W3C Validator , this is valid HTML5:

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<a><span>text</span></a>
</body>
</html>

So: yes , that's valid in HTML5.

What would be the best way to style a portion of the text inside of a link an alternate color?

Use CSS! If your markup looks something like this:

<a><span>Normal text,</span> <span class="abby-normal">different text</span></a>

Then your CSS might look something like this:

a > span.abby-normal {
    color: #F00;
}

Now, if Blücher was a valid color...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM