为什么某些名称(例如 none 与 hide 以及 href 与 src)在 CSS 和 HTML 中如此不一致?

发布于 2024-12-03 10:15:14 字数 566 浏览 1 评论 0原文

你好,这更多的是一个概念性问题。 W3C 如何决定使用隐藏?我这么问是因为我是一名 ESL 人士(英语作为第二语言)。如果我使用overflow:hidden,那么也可以使用overflow:nonedisplay: nonevisibility: hide 也是如此。难道不能只是 display: nonevisibility: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┼── 2024-12-10 10:15:14

这些实体(元素、特性、特性等)之所以被命名为不同的事物,是因为它们服务于不同的目的。让我们从顶部开始并查看您的示例。

显示与可见性

display: none;
visibility: hidden;

正如您从 CSS 2.1 规范 中看到的,值 < code>none 用于许多不同的属性,以指示不应显示属性的视觉方面。因此,如果属性为 float,则 none 表示该元素不是浮动的。对于属性显示,< code>none 表示不显示。

对于可见性hide 是不同的,因为它与 display 不同,不会影响元素流。元素的盒子仍将被渲染,但它将是不可见的。如果您将值 none 赋予 visibility,那么它在语义上的含义与 display: none 完全相同,但事实并非如此。

溢出

overflow: hidden;
overflow: none;

这些意味着不同的事情。 hidden表示超出元素大小的内容将被裁剪,而none表示不进行溢出控制;实际上关闭了溢出。 none 不是 的有效值Overflow,但在本例中,visible 具有相同的效果。

Src 与 href

<script src="file.js">
<link href="file.css">

scriptlink 之间的区别在于,虽然 script 的主要目的是嵌入(内联或通过引用)通过 src 属性)HTML 文档中的脚本,link 的目的是引用万维网上的其他 URI。事实上,使用 link 来引用 CSS 样式表并不是很直观;更直观的解决方案可能是:

<style src="file.css" />

我不知道为什么 HTML 工作组选择使用 link 而不是 style 的详细信息,但通过一点点挖掘,似乎 link 元素已存在于 HTML 1.0HTML 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

display: none;
visibility: hidden;

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 is float, none means the element isn't floating. For the property display, none means it's not displaying.

For visibility, hidden is different, since it unlike display, doesn't affect element flow. The element's box will still be rendered, but it will be invisible. If you gave the value none to visibility, it would semantically mean the exact same thing as display: none, which it isn't.

Overflow

overflow: hidden;
overflow: none;

These mean different things. hidden says that the content that overflows the size of the element will be clipped, while none says that there is no overflow control; in effect turning overflow off. none is not a valid value for overflow, but in this case, visible has the same effect.

Src vs. href

<script src="file.js">
<link href="file.css">

The difference between script and link is that while a script's main purpose is to embed (either inline, or through reference via the src attribute) a script inside the HTML document, the purpose of link is to refer to other URIs on the world wide web. The fact that you use link to refer to a CSS stylesheet is not very intuitive; a more intuitive solution might be:

<style src="file.css" />

I don't have the details on why the HTML Working Group chose to use link and not style, but from a little bit of digging, it seems that the link element was already present in HTML 1.0 and HTML 2.0 and that style 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文