dom属性和html属性
Attributes are used to provide additional information of a tag such as it’s alignments, color, size of the text and other. The attributes are given with the tag that is between the angular brackets after the tag name. The attributes have a name and a value. The attribute value is given after the name of the attribute with an equals to the symbol. The attributes are specified with the starting tag of the element. The value of the attribute is generally given within the double-quotes. The value could also be specified in single quotations.
属性用于提供标签的其他信息,例如标签的对齐方式,颜色,文本大小等。 在标签名称后的尖括号之间的标签中给出了属性。 属性具有名称和值。 属性值在属性名称后给出,并带有等于符号的符号。 使用元素的开始标记指定属性。 属性的值通常在双引号内给出。 该值也可以用单引号指定。
Example:
例:
<FONT SIZE="10"> A TEXT </FONT>
In the above example, the FONT is the element tag and the SIZE is the attribute for the tag FONT. The attribute SIZE specifies the property of the font which is visible for the content of the font tag "A TEXT". The size has been assigned a value of "10".
在上面的示例中, FONT是元素标签, SIZE是标签FONT的属性。 属性SIZE指定字体的属性,该属性对于字体标签“ A TEXT”的内容可见。 大小已分配为值“ 10” 。
一些常用属性 (Some commonly used attributes)
1) The HEIGHT and WIDTH attribute
1)HEIGHT和WIDTH属性
The height and width attribute specifies these properties of the element for which it has been used, and they receive the values in pixels. An example to illustrate the height attribute is as follows:
height和width属性指定已为其使用元素的这些属性,并且它们接收以像素为单位的值。 一个说明height属性的示例如下:
<img src="yourimage.jpg" height="42">
The above code would generate an image with a height of 10px despite its actual height.
上面的代码将生成一个尽管实际高度为10px的图像。
An example to illustrate the width attribute is as follows:
举例说明width属性,如下所示:
<img src="yourimage.jpg" width="42">
2) The HREF attribute
2)HREF属性
The href attribute, it specifies the tag the URL of a page where the link has to, also the href attribute is also used to specifies the base URL for all the other related URLs for that page.
href属性,它指定链接必须指向的页面URL的标签, href属性也用于指定该页面所有其他相关URL的基本URL。
<a href="https://www.yourlink.com">Visit me</a>
The href attribute could also be applied to the anchor (a), AREA, BASE and many other tags.
href属性也可以应用于锚点( a ),AREA,BASE和许多其他标签。
3) The SRC attribute
3)SRC属性
The src attribute specifies the location or the URL of the required file which is present at some external source. The file that is specified could be any file such as an image or an audio or any other media file. Below example illustrate the use of src to specify the image address.
src属性指定在某些外部源上存在的所需文件的位置或URL。 指定的文件可以是任何文件,例如图像或音频或任何其他媒体文件。 下面的示例说明了使用src指定图像地址。
<img src="yourlocationthenimagename.jpg">
Another example of the src attribute is when it used to specify a file for the script element.
src属性的另一个示例是何时用于为脚本元素指定文件。
<script src="myscripts.js"></script>
4) The STYLE attribute
4)STYLE属性
The style attribute is used to specify the style for HTML, that is the presentation of the content on the webpage. It gives the inline style to the element. The style attribute could be used for most of the elements as it affects the display of that element.
style属性用于指定HTML的样式,即网页上内容的表示形式。 它为元素提供了内联样式。 样式属性可用于大多数元素,因为它会影响该元素的显示。
Example:
例:
<p style="color:green">This is a paragraph.</p>
5) The ALT attribute
5)ALT属性
The alt attribute is used to specify a piece of alternative information to the element. This alternative information could be for an image if in case the image is not displayed to the user.
alt属性用于为元素指定一条替代信息。 如果未将图像显示给用户,则该替代信息可以用于图像。
Example:
例:
<img src="yourimage.jpg" alt=" AN IMAGE ">
The other tags where the alt attribute could be used are INPUT and AREA tags.
可以使用alt属性的其他标签是INPUT和AREA标签。
翻译自: https://www.includehelp.com/html/html-attributes.aspx
dom属性和html属性