简体   繁体   English

元素验证错误<br>在<ul><li>元素</li></ul>

[英]Wrong validation on element <br> in <ul> <li> elements

i have this situation:我有这种情况:

...
<ul>
  <li>Text<br/>Text</li><br />
  <li>Text<br/>Text</li>
</ul>
...

Looking for vw3c validation i get:寻找 vw3c 验证我得到:

Error: Element br not allowed as child of element ul in this context.错误:在此上下文中,不允许元素 br 作为元素 ul 的子元素。 (Suppressing further errors from this subtree.) (抑制来自该子树的更多错误。)

Looking next in validator i read too:在验证器中查看下一个我也读到:

Contexts in which element br may be used:
    Where phrasing content is expected.

So, not right if correct or not?那么,正确与否都不正确? How i can fix this?我该如何解决这个问题?
Thanks.谢谢。

<ul> <li>Text<br/>Text</li><br /> <li>Text<br/>Text</li> </ul>

The error message says that you can't have a br element as a child of a ul element.错误消息说您不能将br元素作为ul元素的子元素。

You have one between the two li elements where it isn't allowed.您在两个li元素之间有一个是不允许的。

Remove it.去掉它。


Line breaks are supposed to break a line of text and are semantically useful mostly for things like poetry where explicit line breaks are important.换行符应该打破一行文本,并且在语义上主要用于诗歌等明确的换行符很重要的事情。

List items are block elements and create line breaks automatically, there is no need to put an explicit break between them.列表项是块元素并自动创建换行符,无需在它们之间放置显式换行符。

If you are trying to simulate a margin, then use a real margin (applied to the li element with CSS).如果您尝试模拟边距,请使用真实边距(通过 CSS 应用于 li 元素)。

 li:not(:first-child) { margin-top: 1em; }
 <ul> <li>Text<br/>Text</li> <li>Text<br/>Text</li> </ul>

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

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