关于标题/ Alt属性; [英] About the Title/Alt attributes;

查看:99
本文介绍了关于标题/ Alt属性;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我可以发表这一点。



我理解title和alt属性的用途,但我不明白它们的最佳用途,或者if我可以多次使用相同的标题/替换项。



例如一个关于狗的网站:

根据我的理解,所有img标签都需要一个alt标签:

p>

 < img src =Husky.pngalt =Husky/> 
< img src =Rottweiler.pngalt =Rottweiler/>

对同一主题的多张图片使用相同的alt标签是一种很好的做法

 < img src =Husky2.pngalt =Husky/> 
< img src =Husky3.pngalt =Husky/>
< img src =Husky4.pngalt =Husky/>

在每个标签中使用title / alt标签是否是好习惯?



例子:

















 < ol title =This Dog> 
< li title =这只狗>狗< / li>
< li title =这只狗>狗< / li>
< li title =这只狗>狗< / li>
< li title =这只狗>狗< / li>
< li title =这只狗>狗< / li>
< / ol>

< div id =body>
< p title =这只狗> < / p为H.
< p title =这只狗> < / p为H.
< p title =这只狗> < / p为H.
< p title =这只狗> < / p为H.
< / div>

我的理解是标题标签充当工具提示/鼠标悬停在较新的信息类型的东西上浏览器和alt标签用于在旧版浏览器中执行相同的操作。它们也可以作为搜索引擎识别您的网站的一种方法。



我希望自己的问题能够理解。


不, title 和 alt 属性具有不同的含义/目的(不是旧方法与新方法)。




title



title 属性全局属性,这意味着您可以在全部元素。一般来说(注意一个元素(例如 abbr 元素)它有一个特殊的含义),它被定义为:


标题属性代表元素[...]的建议信息


您应该阅读属性的定义,它解释了它应该如何使用(不)。



alt



alt 属性只能用于 area input (图片按钮)和 img 元素。对于 img ,它有含义

lockquote

code> alt 属性是 img 元素的后备内容,并为无法处理图像或具有图像的用户和用户代理提供等效内容加载被禁用。


很多规则你应该如何(不)使用这个属性。






因此, alt 属性是图片的替代 EITHER 您会看到图片,您可以阅读替代文字。 alt 值应不能作为图片的添加项提供/呈现。



title 属性给出了附加信息,这些信息将提供给两个(看到图像阅读替代文字的用户)。但是,您不应该使用 title 属性作为重要信息的唯一方式,因为...




  • ...典型的演示文稿通常在工具提示后面隐藏(用户不一定知道工具提示完全存在,因为它们不会将鼠标悬停在所有元素上)
  • ...键盘或触摸屏用户通常根本无法看到工具提示,因为他们无法悬停

  • ...屏幕阅读器通常不会读取/宣布标题值(在默认设置中)


I hope I can post this.

I understand the the purpose of the title and alt attributes, but I just do not understand the best use for them or if I can use the same title/alt more than once.

For Example a website about dogs:

From my understanding all img tags need an alt tag:

<img src="Husky.png" alt="Husky"  />
<img src="Rottweiler.png" alt="Rottweiler" />

Is it good practice to use the same alt tag for multiple pictures on the same subject

<img src="Husky2.png" alt="Husky"  />
<img src="Husky3.png" alt="Husky"  />
<img src="Husky4.png" alt="Husky"  />

Is it good practice to use a title/alt tag in every tag? What about using the same tag more than a few times?

Example:

<ol title="This Dog">
<li title="This Dog"> Dogs </li>
<li title="This Dog"> Dogs </li>
<li title="This Dog"> Dogs </li>
<li title="This Dog"> Dogs </li>
<li title="This Dog"> Dogs </li>
</ol>

<div id="body">
<p title="This Dog"> </p> 
<p title="This Dog"> </p> 
<p title="This Dog"> </p> 
<p title="This Dog"> </p> 
</div>

My understanding is that the title tag acts as a tool tip/hover over information type of thing in newer browsers and the alt tags use to do the same back in the older browsers. They also serve as a method for search engines to recognize your website.

I hope I made sense in my questions.

解决方案

My understanding is that the title tag acts as a tool tip/hover over information type of thing in newer browsers and the alt tags use to do the same back in the older browsers.

No, the title and alt attributes have a different meaning/purpose (not old method vs. new method).


title

The title attribute is a global attribute, which means that you can use it on all elements. In general (note that one some elements (e.g. the abbr element) it has a special meaning) it is defined as:

The title attribute represents advisory information for the element […]

You should read the definition of the attribute, it explains how it should (not) be used.

alt

The alt attribute can only be used on the area, input (for image buttons) and img element. For img, it has this meaning:

the value of the alt attribute is the img element’s fallback content, and provides equivalent content for users and user agents who cannot process images or have image loading disabled.

There are many rules how you should (not) use this attribute.


So, the alt attribute is an alternative to the image: EITHER you see the image OR you read the alternative text. The alt value should not be given/presented as an addition to the image.

The title attribute gives additional information, that would be provided to both (the users that see the image and the users that read the alternative text). However, you shouldn't use the title attribute as the only means for information of importance, because …

  • … the typical presentation is often "hidden" behind a tooltip (users don't necessarily know that a tooltip is present at all, because they don't hover over all elements)
  • … keyboard or touchscreen users often cannot see the tooltip at all, because they can't hover
  • … screen readers often don't read/announce the title value (in the default settings)

这篇关于关于标题/ Alt属性;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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