HTML属性

HTML Attributes

All HTML elements can have attributes
Attributes provide additional information about an element
Attributes are always specified in the start tag
Attributes usually come in name/value pairs like: name="value" 属性总是以名称/值对的形式出现,比如:name="value"。
双引号是最常用的,不过使用单引号也没有问题。
提示: 在某些个别的情况下,比如属性值本身就含有双引号,那么您必须使用单引号,例如:name='John "ShotGun" Nelson'

  • The href Attribute
    <a href="https://www.w3schools.com">This is a link</a> ---> This is a link

  • The src Attribute
    <img src="img_girl.jpg">

  • The width and height Attributes
    <img src="img_girl.jpg" width="500" height="600"> --> The image size is specified in pixels: width="500" means 500 pixels wide.

  • The alt Attribute (The alt attribute specifies an alternative text to be used, when an image cannot be displayed.The value of the attribute can be read by screen readers. This way, someone "listening" to the webpage, e.g. a blind person, can "hear" the element.)
    <img src="img_girl.jpg" alt="Girl with a jacket"> --> If we try to display an image that does not exist, the value of the alt attribute will be displayed instead.

  • The style Attribute (The style attribute is used to specify the styling of an element, like color, font, size etc.)
    <p style="color:red">I am a paragraph</p>

  • The lang Attribute (The language of the document can be declared in the <html> tag. The language is declared with the lang attribute. Declaring a language is important for accessibility applications (screen readers) and search engines.)

<!DOCTYPE html>
<html lang="en-US">
<body>

...

</body>
</html>
  • The title Attribute (Here, a title attribute is added to the <p> element. The value of the title attribute will be displayed as a tooltip when you mouse over the paragraph.)
<p title="I'm a tooltip">
This is a paragraph.
</p>

Summary

  • All HTML elements can have attributes
  • The title attribute provides additional "tool-tip" information
  • The href attribute provides address information for links
  • The width and height attributes provide size information for images
  • The alt attribute provides text for screen readers

Attribute Description

alt Specifies an alternative text for an image, when the image cannot be displayed
disabled Specifies that an input element should be disabled
href Specifies the URL (web address) for a link
id Specifies a unique id for an element 定义元素的唯一id
src Specifies the URL (web address) for an image
style Specifies an inline CSS style for an element 规定元素的行内样式(inline style)
title Specifies extra information about an element (displayed as a tool tip) 描述了元素的额外信息 (作为工具条使用)

A complete list of all attributes for each HTML element, is listed in our: HTML Attribute Reference.
更多 HTML 标准属性说明: HTML 标准属性参考手册.

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 8,114评论 0赞 10
  • 进取的兔兔~
    小微绘话阅读 316评论 0赞 1
  • Glide的缓存策略 前言 众所周知,图片加载框架的基本模式就是三层缓存。内存、文件和网络。所有图片加载框架的基本...
    oceanLong阅读 748评论 4赞 5
  • 前言 本见书上JavaScript事件一块较为繁琐细节甚多以为是要花上好一段时间才能学完再来做笔记。结果是当天晚上...
    Alander阅读 235评论 0赞 1

友情链接更多精彩内容