搜索
首页web前端html教程HTML 中的 Alt 标签

HTML 中的 Alt 标签

Sep 04, 2024 pm 04:33 PM
htmlhtml5HTML TutorialHTML PropertiesHTML tags

HTML img 标签包含 alt 属性。该属性指定有关图像的信息,如图像名称、图像链接、图像作者、图像规范等。该属性的主要目的是当互联网连接速度较慢时,图像可能无法加载,但可以正常加载。因此,如果用户将光标从页面上移开,它会显示一些有关图像的文本,而不是用户从它们那里返回;因此,他可以理解该页面上有一些内容,并等待一段时间直到页面加载。

实时场景:当我们在网络上显示任何图像时,在不知道图像内容的情况下对最终用户来说是不公平的。所以我们必须使用 alt 属性为图像指定一些内容。

Alt 属性在 HTML 中如何工作?

Alt 属性为图像提供替代信息以识别图像的含义。该属性仅允许文本。此属性在标签中可用:

这 3 个标签 alt 属性仅用于在图像顶部显示文本。

语法 #1 – HTML 中的 Alt 标签;标签

<img src="/static/imghwm/default1.png" data-src="3.jpg" class="lazy" alt="HTML 中的 Alt 标签">

语法 #2 – 标签

<img src="/static/imghwm/default1.png" data-src="3.jpg" class="lazy" alt="HTML 中的 Alt 标签" usemap="#name">
//usemap name and map name attribute name must be same
<map name="name">
<area coords="specify 4 coordinates" href="file.htm" alt="HTML 中的 Alt 标签">
</map>
<input> tag

语法 #3 – ;标签

<input type="image" alt="HTML 中的 Alt 标签">

在 HTML 中实现 Alt 标签的示例

以下是提到的示例:

示例#1

代码:



<meta charset="ISO-8859-1">
<title>Alt Attribute</title>
<style type="HTML 中的 Alt 标签/css">
h1 {
color: blue;
HTML 中的 Alt 标签-align: center;
}
p {
color: fuchsia;
font-size: 20px;
border: 2px solid red;
}
/*Aligning images side by side*/
* {
box-sizing: border-box;
}
.column {
width: 33.33%;
padding: 5px;
float: left;
}
.row::after {
clear: both;
display: table;
content: "";
}
</style>


<h1 id="Alt-Attribute-Introduction">Alt Attribute Introduction</h1>
<p>HTML img tag contains alt attribute. This attributes specifies
the information about the image like image name, image link, image
author, image specification etc. The main purpose of this attribute is
when the internet connection is slow the image may not load but is
loaded without any problem. So instead of user go back from the if
user moved his cursor from the page it will display some HTML 中的 Alt 标签
regarding image therefore he can understand that there is some content
in this page and wait for some time until page is loaded.</p>
<h1 id="Images-with-img-tag-and-alt-attribute">Images with img tag and alt attribute</h1>
<div class="row">
<div class="column">
<img src="/static/imghwm/default1.png" data-src="3.jpg" class="lazy" alt="First Bird"   style="max-width:90%">
</div>
<div class="column">
<img src="/static/imghwm/default1.png" data-src="4.jpg" class="lazy" alt="Second Bird"   style="max-width:90%">
</div>
<div class="column">
<img src="/static/imghwm/default1.png" data-src="5.jpg" class="lazy" alt="Third Bird"   style="max-width:90%">
</div>
</div>

输出:

如果图片资源可用:

HTML 中的 Alt 标签

如果图片资源不可用:

HTML 中的 Alt 标签

示例#2

代码:



<meta charset="ISO-8859-1">
<title>Alt Attribute</title>
<style type="HTML 中的 Alt 标签/css">
h1 {
color: green;
HTML 中的 Alt 标签-align: center;
}
p {
color: navy;
font-size: 20px;
border: 2px solid orange;
}
</style>


<h1 id="Alt-Attribute-Introduction">Alt Attribute Introduction</h1>
<p>HTML img tag contains alt attribute. This attributes specifies
the information about the image like image name, image link, image
author, image specification etc. The main purpose of this attribute is
when the internet connection is slow the image may not load but is
loaded without any problem. So instead of user go back from the if
user moved his cursor from the page it will display some HTML 中的 Alt 标签
regarding image therefore he can understand that there is some content
in this page and wait for some time until page is loaded.</p>
<h1 id="Images-with-area-tag-and-alt-attribute">Images with area tag and alt attribute</h1>
<img src="/static/imghwm/default1.png" data-src="d2.jpg" class="lazy"    style="max-width:90%"  style="max-width:90%" alt="HTML 中的 Alt 标签" usemap="#dog">
<map name="dog">
<area shape="rect" coords="0,0,81,125" href="https://www.educba.com/category/software-development/software-development-tutorials/python-tutorial/" alt="Python">
<area shape="circle" coords="91,59,4" href="https://www.educba.com/category/software-development/software-development-tutorials/java-tutorial/" alt="Java">
<area shape="circle" coords="125,59,9" href="https://www.educba.com/category/software-development/software-development-tutorials/bootstrap-tutorial/" alt="Bootstrap">
</map>

输出:

如果图片资源可用:

HTML 中的 Alt 标签

HTML 中的 Alt 标签

如果图片资源不可用:

HTML 中的 Alt 标签

HTML 中的 Alt 标签

示例 #3

代码:



<meta charset="ISO-8859-1">
<title>Alt Attribute</title>
<style type="HTML 中的 Alt 标签/css">
h1 {
color: green;
HTML 中的 Alt 标签-align: center;
}
p {
color: navy;
font-size: 20px;
border: 2px solid orange;
}
label, input {
color: green;
font-size: 20px;
}
</style>


<h1 id="Alt-Attribute-Introduction">Alt Attribute Introduction</h1>
<p>HTML img tag contains alt attribute. This attributes specifies
the information about the image like image name, image link, image
author, image specification etc. The main purpose of this attribute is
when the internet connection is slow the image may not load but is
loaded without any problem. So instead of user go back from the if
user moved his cursor from the page it will display some HTML 中的 Alt 标签
regarding image therefore he can understand that there is some content
in this page and wait for some time until page is loaded.</p>
<h1 id="Images-with-input-tag-and-alt-attribute">Images with input tag and alt attribute</h1>

输出:

如果图片资源可用:

HTML 中的 Alt 标签

如果图片资源不可用:

HTML 中的 Alt 标签

结论

Alt是area、img和input标签中可用的属性。此 alt 属性用于提供有关图像的信息,例如什么是图像或图像坐标、图像作者等。

以上是HTML 中的 Alt 标签的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
如何在 Bootstrap 4 中实现多项目轮播?如何在 Bootstrap 4 中实现多项目轮播?Apr 30, 2025 pm 03:24 PM

在Bootstrap4中实现多项目轮播的解决方案在Bootstrap4中实现多项目轮播并不是一件简单的事情。虽然Bootstrap...

deepseek官网是如何实现鼠标滚动事件穿透效果的?deepseek官网是如何实现鼠标滚动事件穿透效果的?Apr 30, 2025 pm 03:21 PM

如何实现鼠标滚动事件穿透效果?在我们浏览网页时,经常会遇到一些特别的交互设计。比如在deepseek官网上,�...

HTML 视频的播放控件样式怎么修改HTML 视频的播放控件样式怎么修改Apr 30, 2025 pm 03:18 PM

无法直接通过CSS修改HTML视频的默认播放控件样式。1.使用JavaScript创建自定义控件。2.通过CSS美化这些控件。3.考虑兼容性、用户体验和性能,使用库如Video.js或Plyr可简化过程。

在手机上使用原生select会带来哪些问题?在手机上使用原生select会带来哪些问题?Apr 30, 2025 pm 03:15 PM

在手机上使用原生select的潜在问题在开发移动端应用时,我们常常会遇到选择框的需求。通常情况下,开发者倾...

在手机上使用原生select的弊端是什么?在手机上使用原生select的弊端是什么?Apr 30, 2025 pm 03:12 PM

在手机上使用原生select的弊端是什么?在移动设备上开发应用时,选择合适的UI组件是非常重要的。许多开发者�...

如何使用Three.js和Octree优化房间内第三人称漫游的碰撞处理?如何使用Three.js和Octree优化房间内第三人称漫游的碰撞处理?Apr 30, 2025 pm 03:09 PM

使用Three.js和Octree优化房间内第三人称漫游的碰撞处理在Three.js中使用Octree实现房间内的第三人称漫游并添加碰�...

在手机上使用原生select会遇到哪些问题?在手机上使用原生select会遇到哪些问题?Apr 30, 2025 pm 03:06 PM

使用原生select在手机上的问题在移动设备上开发应用时,我们经常会遇到需要用户进行选择的场景。虽然原生sel...

为什么有的网站能实现鼠标滚动穿透效果,而有的不行?为什么有的网站能实现鼠标滚动穿透效果,而有的不行?Apr 30, 2025 pm 03:03 PM

探究鼠标滚动事件的实现原理在浏览一些网站时,你可能注意到某些页面元素在鼠标悬停时仍然允许滚动整个页...

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

功能强大的PHP集成开发环境

mPDF

mPDF

mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

SecLists

SecLists

SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。