在HTML中的图像上指定width和heigth属性仍然是相关的吗? [英] Is it still relevant to specify width and heigth attribute on images in HTML?

查看:106
本文介绍了在HTML中的图像上指定width和heigth属性仍然是相关的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现一个类似的问题这里,回答为: 应该始终在图片标签中定义宽度和高度。但它是从2009年。

I found a similar question here, with the answer: "you should always define the width and height in the image tag." But it is from 2009.

在此期间,许多事情在前端改变了。我们现在都在做响应页面设计,同时为许多设备和大小(移动,平板电脑,桌面...)。

In the meantime, many things has changed on frontend. We are all doing responsive page design now, for many devices and sizes simultaneously (mobile, tablet, desktop...).

因此,我想知道是否还需要指定在2016年的宽度和高度属性,以及为什么原因(为响应,页面速度,SEO ...)?

So, I wonder is it still necessary to specify the width and height attributes in 2016, and for what reason (for responsive, page speed, SEO...)?

推荐答案

img 元素具有width和height属性,但在 DOCTYPE 下不需要。

An img element has width and height attributes, but they're not required under any DOCTYPE.

宽度和高度属性只是必需或相关,以保留页面上的空间,并防止页面在加载时移动 - 这很重要。这可以使用CSS,而不是提供CSS负载足够快 - 它很可能在图像之前加载,所以应该是好的。

Width and height attributes were only 'required' or relevant to reserve the space on the page and prevent the page moving around as it loads - which is important. This can be achieved using CSS instead providing the CSS loads quickly enough - it is likely to load before the images anyway, so all should be good.

也可以实现。和有效)只指定一个属性,宽度或高度,浏览器将计算省略的值,以保持正确的长宽比。

It is also possible (and valid) to specify just one attribute, width or height and the browser will calculate the omitted value in order to maintain the correct aspect ratio.

您可以指定百分比值属性(如果需要)。你不需要使用CSS为此,如果这是你所暗示的。

You can specify percent values in the attributes if required. You don't need to use CSS for this, if that is what you are implying.

此外,在HTML5下,宽度和高度只能取一个像素值,换句话说,有效的非负整数。

Also, it is relevant to add - Under HTML5 the width and height can only take a pixel value, in other words a valid non-negative integer.

是否使用width和height属性取决于您的设计。如果你有很多不同大小的图片,你想把所有的维度在CSS中,或包含它们与img?

Whether you use the width and height attributes can depend on your design. If you have lots of differently sized images, do you want to lump all the dimensions in the CSS or include them with the img?

这篇关于在HTML中的图像上指定width和heigth属性仍然是相关的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆