简体   繁体   English

<li>中允许的标签是什么?

[英]What are the allowed tags inside a <li>?

I have been searching for the list of tags that are available inside a <li> , but I couldn't find any reference. 我一直在搜索<li>中可用的标签列表,但我找不到任何参考。

Is it possible that any standards-compliant HTML 4+ block element is allowed in them? 是否可以在其中允许任何符合标准的HTML 4+块元素?

TL;DR : an <li> can contain any element that is valid in <body> . TL; DR<li>可以包含<body>有效的任何元素。

In the HTML 4.01 spec for lists you'll find the relevant extract of the DTD: 列表HTML 4.01规范中,您将找到DTD的相关摘录:

<!ELEMENT LI - O (%flow;)* -- list item -->

This specifies that an <li> may contain flow content , which is the collection of all block and inline elements. 这指定<li>可以包含流内容 ,该内容是所有内联元素的集合。

The HTML5 spec for an <li> is the same in that it also allows any flow content . <li>HTML5规范是相同的,因为它还允许任何流内容

It's a block level element so pretty much anything goes. 这是一个块级元素,所以几乎任何东西都可以。 Trouble only comes when you're putting block level elements inside inline ones. 只有在将块级元素放入内联元素时才会出现问题。

Yup, pretty much. 是的,差不多。 You can have lists inside lists ( either inside the <li> or just loose inside the <ol> / <ul> the inner list must be inside an <li> ), block elements and inline elements. 您可以在列表中包含列表( <li>内部或只是在 <ol> / <ul> 内部 松散 ,内部列表必须在<li> ),块元素和内联元素。

To me it wouldn't make much sense to put a <table> inside an <li> , but even that's still valid. 对我来说,将<table>放在<li>是没有多大意义的,但即使这样仍然有效。

You can use the W3C's Markup Validation Service to test against your cases to know whether or not your markup is valid. 您可以使用W3C的标记验证服务来测试您的案例,以了解您的标记是否有效。

This validator checks the markup validity of Web documents in HTML, XHTML, SMIL, MathML, etc. 此验证器检查HTML,XHTML,SMIL,MathML等Web文档的标记有效性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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