UL 标签周围的垂直间距
标记与
或
标记之间的意外差异之一是列表标记在块的顶部和底部添加 20px 的填充到样式属性中指定的内容。事实上,使用
可以准确地给出所需的结果。尽管这种解决方法显然是非法的(问题2031725)。我猜这个解决方法正是发帖者所想的。
Firefox/Safari/IE 也有这种行为。这个问题是否源于HTML规范?还有另一个明显的解决方法吗?这似乎是一个明显的缺陷,我听到了很多抱怨。
One of the unintended differences between a <div>
tag and a <ol>
or <ul>
tag is that the list tags add 20px of padding at the top and bottom of the block to whatever is specified in the style properties.
In fact, using a <div><li></li><li></li></div>
gives exactly the desired results. Although this workaround is apparently illegal- (question 2031725). I'm guessing this workaround is what the poster had in mind.
Firefox/Safari/IE share this behavior. Does this problem originate in the HTML specification? Is there another obvious work-around? This seems like an obvious flaw and I hear lots of complaints.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
和
标记周围的垂直空间不是 HTML 的一部分,而是浏览器默认样式的一部分。如果您不喜欢这种样式,请更改它而不是使用无效的 HTML。
我也反对“无意的差异”。
和
具有固有的语义含义(分别是有序列表和无序列表),因此浏览器默认设置它们的样式以支持该含义。
(几乎)根本没有语义含义,因此默认情况下是无样式的。
The vertical space around
<ol>
and<ul>
tags is not part of HTML, but of browsers' default styling. If you don't like the style, change it rather than using invalid HTML.I'd also argue against "unintended differences".
<ol>
and<ul>
have inherent, semantic meaning (that of ordered and unordered lists, respectively) and so browsers by default style them to support that meaning.<div>
has (almost) no semantic meaning at all, so is unstyled by default.