我的 HTML INPUT 不是有效的标记,请帮助
在我的网站上,我有以下代码:
<input type="image" src="images/btn.png" alt="Submit" border="0" height="25" width="102" />
当我通过众多 HTML 验证器之一运行我的网站时,它们会提示通知我:
- 边框
- 高度
- 宽度
是 INPUT 元素的无效属性。
然而,YSlow 和 Google PageSpeed 告诉我,我应该始终包含图像尺寸,以提高解析 HTML 的速度。
还有什么其他方法可以让我使用图像提交按钮,同时仍然保持 HTML 有效并遵循 YSlow 建议?
On my web site, I have the following code:
<input type="image" src="images/btn.png" alt="Submit" border="0" height="25" width="102" />
When I run my web site through one of the many HTML validators, they prompt to inform me that:
- border
- height
- width
are invalid attributes of the INPUT element.
However, YSlow and Google PageSpeed inform me that I should always include image dimensions to improve the speed up of parsing HTML.
What other way exists for me to use an image submit button while still being HTML valid and following YSlow recommendations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 CSS 来达到同样的目的。 内联 CSS:
或者更好的是,在 CSS 文件中使用样式:
HTML:
CSS:
如果 yslow 或 Google PageSpeed 仍然抱怨,请忽略。
Use CSS to achieve the same goal. Either inline CSS:
or even better yet, with a style in your CSS file:
HTML:
CSS:
If yslow or Google PageSpeed still complains, ignore.
验证和解析速度是两个不同的东西,这三个工具各有侧重。
关于验证器上的警告,这是因为没有规范包含这些标签上的此类信息,并且可以使用 CSS 而不是 HTML 添加它们。
Validation and parsing speed are two different things, those three tools are right on their own focus.
Regarding the warning on the validator, those are because there are no specification that includes that kind of information on those tags, and they can be added with CSS instead of HTML.
您应该通过 CSS 外部文件添加这些内容,因为 HTML 验证器会进行检查以确保未设置样式值。
验证背后的想法是页面应该能够在没有任何 CSS 的情况下查看。 但是,Google Page 速度背后的想法是使页面加载速度最快。
如果您使用 CSS 添加这些声明,则应该能够通过验证器。 只要您正确调整了实际图像文件的大小,加载时间也应该没问题。
You should add these via a CSS External File because HTML validators check to make sure no styling values are set.
The idea behind validation is that the page should be able to be viewed without any CSS. But, the idea behind Google Page speed is to make the page load the fastest.
If you add these declarations using CSS, you should be able to both pass the validator. As long as you have sized your actual image file correctly, you should be fine on the loading time aswell.
border
、height
和width
不是 W3C 规范的一部分:http://www.w3schools.com/TAGS/tag_input.asp 因此无效。 它们无助于加快 HTML 解析速度,但有助于加快图像渲染速度,因为浏览器不需要计算尺寸。这个增益非常小(取决于您加载的图像数量)。 所以你基本上可以忽略它。 如果您尝试将尺寸定义为图像实际尺寸以外的尺寸,则可以使用 CSS 为其指定尺寸。
border
,height
andwidth
are not a part of the W3C specifications : http://www.w3schools.com/TAGS/tag_input.asp and hence invalid. They don't help speed up HTML parsing, but image rendering, since the browser won't need to calculate the dimensions.This gain is very small (depending on how many images you're loading in). So you can mostly ignore it. You could use CSS to give it the dimensions if you're trying to define them as something other than the image's actual dimensions.