问题
I was wondering if there would be any problems if I added a list inside a H1 heading:
<h1>
<ul>
<li><a href="...">some link</a></li>
<li><a href="...">another link</a></li>
<li>current page</li>
</ul>
</h1>
the list is a "breadcrumb" type navigation.
Or is it better to insert it inside the list?
<ul>
<li><a href="...">some link</a></li>
<li><a href="...">another link</a></li>
<li><h1>current page</h1></li>
</ul>
回答1:
It's not valid to have a ul inside a h1, the best way of checking is to use http://validator.w3.org/ to check your structure, that way the doctype you are using will be considered. (but it's still not valid!)
回答2:
Header elements like <h1>
follow the phrasing content content model: if you wanted to follow the HTML specification to the letter, phrasing content can only contain regular text or other phrasing content. As <ul>
elements aren't phrasing content, they're technically not allowed in <h1>
elements.
Your second example—placing the <h1>
elements within <li>
elements—is valid markup and would be the preferred method of combining <h1>
and <ul>
elements.
回答3:
You can use W3C Markup Validation Service to check out whether or not it is valid :)
回答4:
To answer your original question, no, that doesn't look like a sane thing to do with your markup, and even if it were technically valid (which I don't believe it is) I wouldn't advise doing it.
As for SEO, h1
is used to some degree in search, though I believe it's not as important as the <title>
element. However, if your page doesn't have a heading, semantically-speaking, I certainly wouldn't crowbar one in just to try and improve rankings. Put that "current page" text in the <title>
, if appropriate, make the breadcrumb list a normal breadcrumb list, and don't bother with the h1 if you don't need it.
回答5:
this would display - however I think it would be considered bad practice as a list is not a header. You'd be better off adding css styling so you could format you list to the desired size, font etc.
来源:https://stackoverflow.com/questions/5014773/are-uls-allowed-inside-h1