美文网首页
HTML属性

HTML属性

作者: 春暖花开奇奇乐乐 | 来源:发表于2018-06-26 17:46 被阅读10次

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 标准属性参考手册.

相关文章

  • HTML的探索3

    HTML属性 属性为HTML元素提供附加信息 HTML属性 HTML属性 HTML标签可以拥有属性。属性提供了有关...

  • 『Web前端』 HTML入门(5)—— HTML 属性

    HTML 属性 属性为 HTML 元素提供附加信息。 HTML 属性 HTML 标签可以拥有属性。属性提供了有关 ...

  • HTML:基础(3)属性

    HTML 属性 属性是 HTML 元素提供的附加信息。 HTML 属性 HTML 元素可以设置属性 属性可以在元素...

  • HTML 属性

    HTML 属性 属性为HTML元素提供附加信息 HTML标签可以拥有属性。属性提供了HTML元素的更多的信息 属性...

  • HTML属性

    属性为 HTML 元素提供附加信息。 HTML 属性 HTML 标签可以拥有属性。属性提供了有关 HTML 元素的...

  • html属性

    html属性 属性提供有关HTML元素的其他信息。 一、html属性 html元素可以具有属性 属性提供有关元素的...

  • 04_HTML 属性

    前面我们学习了HTML的标签、元素。这次我们来学习HTML 属性。 HTML属性 HTML标签可以拥有属性。属性提...

  • HTML基础知识

    HTML基础知识 HTML的历史:HTML,XHTML HTML的全局属性:全局标准属性,全局事件属性 HTML的...

  • HTML 样式

    HTML 样式 style 属性用于改变 HTML 元素的样式。 HTML 的 style 属性 style 属性...

  • jQuery粗略源码解析5 属性操作

    1 HTML属性操作 .attr() 获取设置HTML属性值 .removeAttr() 移除html属性 2 D...

网友评论

      本文标题:HTML属性

      本文链接:https://www.haomeiwen.com/subject/chvmyftx.html