为什么某些名称(例如 none 与 hide 以及 href 与 src)在 CSS 和 HTML 中如此不一致?
你好,这更多的是一个概念性问题。 W3C 如何决定使用隐藏
与无
?我这么问是因为我是一名 ESL 人士(英语作为第二语言)。如果我使用overflow:hidden
,那么也可以使用overflow:none
。 display: none
和 visibility: hide
也是如此。难道不能只是 display: none
和 visibility: none
吗?因为真正造成差异的是属性 display
和 可见性而不是它们的价值。这更多的是要求解释。例如,类似的“奇怪”的事情会发生:
<script src="file.js">
为什么
<link href="file.css">
它们不同?我了解所有这些在技术上是如何工作的,我只是好奇他们如何决定属性的名称。
谢谢。
Hi, this is more a conceptual question. How did the W3C decide to use hidden
vs. none
? I'm asking because I'm an ESL person (English as a second language). If I'm using overflow: hidden
, overflow: none
could just as well be used. The same goes for display: none
and visibility: hidden
. Couldn't it just have been display: none
and visibility: none
, because what really make the difference is the properties display
and visibility
and not their value. This is more a request for an explanation. Similiar "weird" things happens for example:
<script src="file.js">
and
<link href="file.css">
Why are they different? I understand how all of this works technically, I'm just curious about how they decided the names of the attributes.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些实体(元素、特性、特性等)之所以被命名为不同的事物,是因为它们服务于不同的目的。让我们从顶部开始并查看您的示例。
显示与可见性
正如您从 CSS 2.1 规范 中看到的,值 < code>none 用于许多不同的属性,以指示不应显示属性的视觉方面。因此,如果属性为
float
,则none
表示该元素不是浮动的。对于属性显示
,< code>none 表示不显示。对于
可见性
,hide
是不同的,因为它与display
不同,不会影响元素流。元素的盒子仍将被渲染,但它将是不可见的。如果您将值none
赋予visibility
,那么它在语义上的含义与display: none
完全相同,但事实并非如此。溢出
这些意味着不同的事情。
hidden
表示超出元素大小的内容将被裁剪,而none
表示不进行溢出控制;实际上关闭了溢出。none
不是的有效值Overflow
,但在本例中,visible
具有相同的效果。Src 与 href
script
和link
之间的区别在于,虽然script
的主要目的是嵌入(内联或通过引用)通过src
属性)HTML 文档中的脚本,link
的目的是引用万维网上的其他 URI。事实上,使用link
来引用 CSS 样式表并不是很直观;更直观的解决方案可能是:我不知道为什么 HTML 工作组选择使用
link
而不是style
的详细信息,但通过一点点挖掘,似乎link
元素已存在于 HTML 1.0 和 HTML 2.0 以及样式
直到 HTML 3.0 才引入。围绕样式表语言的讨论早在 1993 年(同年)就开始了HTML 1.0 已经完成),而 HTML 3.0 直到 1995 年才完成,因此他们在
style
元素发明之前就找到了嵌入样式表的方法,这是有道理的。The reason these entities (elements, properties, attributes, etc.) are named different things is because they serve different purposes. Let's start from the top and go through your examples.
Display vs. Visibiliy
As you can see from the CSS 2.1 specification, the value
none
is used for many different properties to indicate that the property's visual aspect should not be shown. So if the property isfloat
,none
means the element isn't floating. For the propertydisplay
,none
means it's not displaying.For
visibility
,hidden
is different, since it unlikedisplay
, doesn't affect element flow. The element's box will still be rendered, but it will be invisible. If you gave the valuenone
tovisibility
, it would semantically mean the exact same thing asdisplay: none
, which it isn't.Overflow
These mean different things.
hidden
says that the content that overflows the size of the element will be clipped, whilenone
says that there is no overflow control; in effect turning overflow off.none
is not a valid value foroverflow
, but in this case,visible
has the same effect.Src vs. href
The difference between
script
andlink
is that while ascript
's main purpose is to embed (either inline, or through reference via thesrc
attribute) a script inside the HTML document, the purpose oflink
is to refer to other URIs on the world wide web. The fact that you uselink
to refer to a CSS stylesheet is not very intuitive; a more intuitive solution might be:I don't have the details on why the HTML Working Group chose to use
link
and notstyle
, but from a little bit of digging, it seems that thelink
element was already present in HTML 1.0 and HTML 2.0 and thatstyle
wasn't introduced until HTML 3.0.As discussions around a style sheet language started as early as in 1993 (the same year HTML 1.0 was completed) and HTML 3.0 wasn't done until 1995, it makes sense that they found a way to embed stylesheets before the
style
element was invented.