[英]W3C validation error with image width
I need an image to resize to the full width of my webpage. 我需要一个图像来调整我的网页的整个宽度。 This works fine with the following HTML/CSS:
这适用于以下HTML / CSS:
#logo{ position: fixed; top: 0; left: 0; min-width: 100%; z-index: 3; opacity: .8; }
<div id="logo"><img src="/logo.png" alt="logo" width="100%"></div>
However W3C validation picks this up as an error. 但是W3C验证认为这是一个错误。 "Bad value 100% for attribute width on element img: Expected a digit but saw % instead."
“元素img上的属性宽度的值为100%:预期数字但是看到了%。”
I tried this alternative, but now the image does not resize of course: 我试过这个替代方案,但现在图像没有调整大小:
<div id="logo"><img src="/logo.png" alt="logo" width:100%;></div>
How do I retain the same effect while still passing the W3C validation? 如何在仍然通过W3C验证的同时保持相同的效果? It is the only error on my entire page, and I know it doesn't really matter, but there is bound to be a solution I am overlooking.
这是我整个页面上唯一的错误,我知道这并不重要,但肯定会有一个我忽略的解决方案。
Kindly use the following code in order for you to have W3C validation 请使用以下代码以便进行W3C验证
<div id="logo"><img src="/logo.png" alt="logo" width="100%" /></div>
(OR) (要么)
<div id="logo"><img src="/logo.png" alt="logo" style="width:100%;" /></div>
Because width attributes does not use % it uses digits like width='100'
, means 100px. 因为宽度属性不使用%,所以它使用
width='100'
类的数字,表示100px。 if you want to apply 100% width on image, use CSS 如果要在图像上应用100%宽度,请使用CSS
#logo img {
width: 100%
}
By reading w3school official documentation 通过阅读w3school官方文档
In HTML 4.01, the width could be defined in pixels or in % of the containing element
在HTML 4.01中,宽度可以以像素或包含元素的%来定义
but also 但是也
In HTML5, the value must be in pixels.
在HTML5中,值必须以像素为单位。
So you can't specify a valid width in percentage for HTML5
, tryo to use style="width:100%"
因此,您无法为
HTML5
指定有效的百分比宽度,请尝试使用style="width:100%"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.