博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
html替换img标签问题_HTML`img`标签
阅读量:2503 次
发布时间:2019-05-11

本文共 2641 字,大约阅读时间需要 8 分钟。

html替换img标签问题

Images can be displayed using the img tag.

可以使用img标签显示图像。

This tag accepts a src attribute, which we use to set the image source:

此标记接受src属性,我们使用它来设置图像源:

We can use a wide set of images. The most common ones are PNG, JPEG, GIF, SVG and more recently WebP.

我们可以使用多种图像。 最常见的是PNG,JPEG,GIF,SVG和最近的WebP。

The HTML standard requires an alt attribute to be present, to describe the image. This is used by screen readers and also by search engine bots:

HTML标准要求存在alt属性来描述图像。 屏幕阅读器和搜索引擎机器人都使用此功能:

A picture of a dog

You can set the width and height attributes to set the space that the element will take, so that the browser can account for it and it does not change the layout when it’s fully loaded. It takes a numeric value, expressed in pixels.

您可以设置widthheight属性来设置元素将要占用的空间,以便浏览器可以考虑它,并且在完全加载时它不会更改布局。 它需要一个数值,以像素为单位。

A picture of a dog

使用srcset响应图像 (Responsive images using srcset)

The srcset attribute allows you to set responsive images that the browser can use depending on the pixel density or window width, according to your preferences. In this way it can only download the resources it needs to render the page, without downloading a bigger image if it’s on a mobile device, for example.

srcset属性使您可以根据自己的喜好,设置浏览器可以根据像素密度或窗口宽度使用的响应图像。 这样,它只能下载呈现页面所需的资源,而如果是在移动设备上,则不能下载更大的图像。

Here’s an example, where we give 4 additional images for 4 different screen sizes:

在以下示例中,我们针对4种不同的屏幕尺寸提供了4张其他图片:

A picture of a dog

In the srcset we use the w measure to indicate the window width.

srcset我们使用w度量来指示窗口宽度。

Since we do so, we also need to use the sizes attribute:

既然这样做,我们还需要使用sizes属性:

A picture of a dog

In this example the (max-width: 500px) 100vw, (max-width: 900px) 50vw, 800px string in the sizes attribute describes the size of the image in relation to the viewport, with multiple conditions separated by a comma.

在此示例中, sizes属性中的(max-width: 500px) 100vw, (max-width: 900px) 50vw, 800px字符串描述与视口有关的图像大小,多个条件之间用逗号分隔。

The media condition max-width: 500px sets the size of the image in correlation to the viewport width. In short, if the window size is < 500px, it renders the image at 100% of the window size.

媒体条件max-width: 500px设置与视口宽度相关的图像大小。 简而言之,如果窗口大小小于500像素,它将以窗口大小的100%渲染图像。

If the window size is bigger but < 900px, it renders the image at 50% of the window size.

如果窗口大小更大但< 900px ,它将以窗口大小的50%渲染图像。

And if even bigger, it renders the image at 800px.

如果更大,它将以800像素渲染图像。

The vw unit of measure can be new to you, and in short we can say that 1 vw is 1% of the window width, so 100vw is 100% of the window width.

vw度量单位可能对您来说是新的,简而言之,我们可以说1 vw是窗口宽度的1%,因此100vw是窗口宽度的100%。

A useful website to generate the srcset and progressively smaller images is .

一个有用的网站,可以生成srcset和逐渐缩小的图像, 为 。

翻译自:

html替换img标签问题

转载地址:http://lqqgb.baihongyu.com/

你可能感兴趣的文章
C++——string类和标准模板库
查看>>
zt C++ list 类学习笔记
查看>>
git常用命令
查看>>
探讨和比较Java和_NET的序列化_Serialization_框架
查看>>
1、jQuery概述
查看>>
数组比较大小的几种方法及math是方法
查看>>
FTP站点建立 普通电脑版&&服务器版
查看>>
js 给一段代码,给出运行后的最终结果的一些综合情况、
查看>>
webservice 详解
查看>>
js自动补全实例
查看>>
VS无法启动调试:“生成下面的模块时,启用了优化或没有调试信息“
查看>>
npm 安装 sass=-=-=
查看>>
WINFORM中加入WPF控件并绑定数据源实现跨线程自动更新
查看>>
C#类对象的事件定义
查看>>
各类程序员学习路线图
查看>>
HDU 5510 Bazinga KMP
查看>>
关于select @@IDENTITY的初识
查看>>
ASP.NET MVC ajax提交 防止CSRF攻击
查看>>
关于CSS伪类选择器
查看>>
适用于带文字 和图片的垂直居中方法
查看>>