(X)HTML+CSS 验证警告
我尝试通过我的 css 验证,但仍然有一些警告,如下所示:
在 (x)HTML+CSS 中,浮动元素需要声明宽度。只有具有固有宽度的元素(html、img、input、textarea、select 或 object)不受影响。
事实上,我不太明白它的真正含义。任何人都可以解释一下吗?
I try to pass my css valiation yet I still have a few warnings like the following:
In (x)HTML+CSS, floated elements need to have a width declared. Only elements with an intrinsic width (html, img, input, textarea, select, or object) are not affected
In fact, I don't understand very well what it relly means. Anyone can explain?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这只是意味着,如果您在没有固有宽度的元素上设置 float 属性,则还需要设置 width 属性。
编辑:此外,W3C 标准已取消该要求。在我看来,您使用的验证引擎可能已经过时了。
It just means that if you set the float property on an element that doesn't have an intrinsic width, you need to also set the width property.
Edit: Also, that requirement has been stricken from the W3C standard. Seems to me like the validation engine you're using could be outdated.
这意味着如果您想在某个元素上应用
float:
属性,则还必须向该元素应用width:
属性It means that if you want to apply a
float:
property on an element, you also have to apply awidth:
property to that same element向没有声明或内置宽度(固有宽度)的元素添加宽度的原因是,浮动元素随后将扩展到父级的整个宽度,并且您会失去通过浮动它想要获得的内容。
The reason for adding width to elements with no declared or built-in width (intrinsic) is because the floated element will then expand to full width of the parent and you lose what you wanted to gain by floating it.
从某种意义上说,这不是验证错误,不像您输入“funt”而不是“font”或忘记关闭括号。它只是告诉你你的 CSS 并没有真正的意义。
如果某个东西要像块元素默认那样占据容器宽度的 100%,那么浮动它有什么意义呢?
In a sense that isn't a validation error, not like you typed "funt" instead of "font" or forgot to close a bracket. It's just telling you that your CSS doesn't really make sense.
What's the point in floating something if it's going to take up 100% of the width of the container anyway, as block elements do by default?