HTML img 标签包含 alt 属性。该属性指定有关图像的信息,如图像名称、图像链接、图像作者、图像规范等。该属性的主要目的是当互联网连接速度较慢时,图像可能无法加载,但可以正常加载。因此,如果用户将光标从页面上移开,它会显示一些有关图像的文本,而不是用户从它们那里返回;因此,他可以理解该页面上有一些内容,并等待一段时间直到页面加载。
实时场景:当我们在网络上显示任何图像时,在不知道图像内容的情况下对最终用户来说是不公平的。所以我们必须使用 alt 属性为图像指定一些内容。
Alt 属性在 HTML 中如何工作?
Alt 属性为图像提供替代信息以识别图像的含义。该属性仅允许文本。此属性在标签中可用:
这 3 个标签 alt 属性仅用于在图像顶部显示文本。
语法 #1 – ;标签
<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>
è¾åºï¼
妿å¾çèµæºå¯ç¨ï¼
妿å¾çèµæºä¸å¯ç¨ï¼
示ä¾#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>
è¾åºï¼
妿å¾çèµæºå¯ç¨ï¼
妿å¾çèµæºä¸å¯ç¨ï¼
ç¤ºä¾ #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>
è¾åºï¼
妿å¾çèµæºå¯ç¨ï¼
妿å¾çèµæºä¸å¯ç¨ï¼
ç»è®º
Altæ¯areaãimgåinputæ ç¾ä¸å¯ç¨ç屿§ãæ¤ alt 屿§ç¨äºæä¾æå ³å¾åçä¿¡æ¯ï¼ä¾å¦ä»ä¹æ¯å¾åæå¾ååæ ãå¾åä½è çã
以上是HTML 中的 Alt 标签的详细内容。更多信息请关注PHP中文网其他相关文章!

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

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

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

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

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

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

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

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


热AI工具

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

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

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

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

热门文章

热工具

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

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

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

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

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