开发者

Tag H3 inside UL tag [duplicate]

开发者 https://www.devze.com 2023-04-06 11:07 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Is anything except LI's allowed in a UL?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Is anything except LI's allowed in a UL?

I was doing something like that:

<ul>
    <h3><a name="titlename">Title</a></h3>
    <li>Text.</li>
    <li>More text.</li>
    <span><a href="/url">Click here</a> to go to some place.</span>
</ul>

But i get warnings in visual studio:

Warning Validation (HTML5): Element 'h3' cannot be nested within element 'ul'.  
Warning Validation (HTML5): Element 'span' cannot be nested within element эul'.    

I googled and found that looks like it is not a problem to have another tags but <li> inside <ul>ю

But anyway may be some one have any opinions on that. Could it break something? do put you <h> tags or any another tags inside &开发者_高级运维lt;ul>? What is your experience with that?


<ul> denotes an unordered list, while <li> denotes a list item that belongs to that unordered list - so it only really makes sense to have <li> elements within a <ul> element. If you want to give the unordered list a title, do it outside of the list (this would be the more 'normal' way), or within an <li> element that is inside the list.

<h3>My List Title</h3>
<ul>
  <li>List items in here...</li>
</ul>


It is invalid if your <h3> is a child of the <ul>. You can only have it inside a <li> but not directly in a <ul>.


You can put inside ot <UL> tag only <LI>. And then in LI you can put what you want.

<ul>
   <li><h3><a name="titlename">Title</a></h3></li>
   <li>Text.</li>
   <li>More text.</li>
   <li><span><a href="/url">Click here</a> to go to some place.</span></li>
</ul>

or

<h3><a name="titlename">Title</a></h3>
<ul>
   <li>Text.</li>
   <li>More text.</li>
</ul>
<span><a href="/url">Click here</a> to go to some place.</span>

Yes, you can put anything you want inside of UL, but it's not by W3C standarts (you can see the validation errors) and nobody will guarantie you that in all browsers it will be displayed properly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号