gpt4 book ai didi

html - HTML 和 CSS 宽度属性有什么区别?

转载 作者:太空狗 更新时间:2023-10-29 14:41:20 24 4
gpt4 key购买 nike

代码可以在这里找到:

http://www.w3schools.com/css/tryit.asp?filename=trycss_float_elements

<!DOCTYPE html>
<html>
<head>
<style>
.thumbnail
{
float:left;
width:110px;
height:90px;
margin:5px;
}
</style>
</head>

<body>
<h3>Image Gallery</h3>
<p>Try resizing the window to see what happens when the images do not have enough room.</p>
<img class="thumbnail" src="klematis_small.jpg" width="107" height="90">
<img class="thumbnail" src="klematis2_small.jpg" width="107" height="80">
<img class="thumbnail" src="klematis3_small.jpg" width="116" height="90">
<img class="thumbnail" src="klematis4_small.jpg" width="120" height="90">
<img class="thumbnail" src="klematis_small.jpg" width="107" height="90">
<img class="thumbnail" src="klematis2_small.jpg" width="107" height="80">
<img class="thumbnail" src="klematis3_small.jpg" width="116" height="90">
<img class="thumbnail" src="klematis4_small.jpg" width="120" height="90">
</body>
</html>

我发现style标签内有width:110px;内也有width="107" img 标签。两者都是必需的吗?(在这种情况下,CSS 似乎覆盖了 HTML 属性)它们之间的区别有任何解释吗?

最佳答案

I checked the documents, but they don't make clear what will happen if both of them are set..

那隐藏在某处here :

The UA may choose to honor presentational attributes in an HTML source document. If so, these attributes are translated to the corresponding CSS rules with specificity equal to 0, and are treated as if they were inserted at the start of the author style sheet. They may therefore be overridden by subsequent style sheet rules. In a transition phase, this policy will make it easier for stylistic attributes to coexist with style sheets.

现在,正如我在幽默评论中暗示的那样,我不确定为什么他们会为 HTML 宽度 img 元素上的属性,并为所有这些元素的 CSS width 属性设置一个不同的值。也许他们正在考虑何时缺少 .thumbnail 类,或者其他原因。 一如既往,Alohci is in a better position to explain why the width and height attributes are specified anyway ,即使它们出于某种原因不同于 CSS 中指定的尺寸。

但是,我可以告诉您的是,这基本上意味着 CSS 确实优先,即使两者都已设置也是如此。

关于html - HTML 和 CSS 宽度属性有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20742675/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com