图像宽度/高度作为属性或CSS? [英] Image width/height as an attribute or in CSS?

查看:73
本文介绍了图像宽度/高度作为属性或CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

指定图片高度和宽度的正确语义方式是什么?在CSS ...

What's the "correct" semantic way to specify image height and width? In CSS...

width:15px;

或内联...

<img width="15"

CSS似乎是放置视觉信息的地方。另一方面,很少有人会认为图像src不应该被指定为属性,并且高度/宽度似乎与src是二进制图像数据绑定。

CSS seems like the right place to put visual information. On the other hand, few would argue that image "src" should not be specified as an attribute and the height/width seem as tied to the binary image data as the "src" is.

(是的,我从一个技术,终端用户的角度来看这真的没有关系。)

(Yes, I realize from a technical, end-user perspective this really doesn't matter.)

推荐答案

它应该内联定义。如果使用img标签,那么该图像应该对内容具有语义价值,这就是为什么验证需要alt属性的原因。

It should be defined inline. If you are using the img tag, that image should have semantic value to the content, which is why the alt attribute is required for validation.

如果图像是布局或模板的一部分,则应使用img标签之外的标签,并将该图像作为CSS背景分配给元素。在这种情况下,图像没有语义,因此不需要alt属性。我相当肯定,大多数屏幕阅读器甚至不知道一个CSS图像存在。

If the image is to be part of the layout or template, you should use a tag other than the img tag and assign the image as a CSS background to the element. In this case, the image has no semantic meaning and therefore doesn't require the alt attribute. I'm fairly certain that most screen readers would not even know that a CSS image exists.

这篇关于图像宽度/高度作为属性或CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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