html属性和css属性
The role
attribute describes the role of an element in programs that can make use of it, such as screen readers or magnifiers.
role
属性描述了元素在可以使用它的程序中的角色,例如屏幕阅读器或放大镜。
Usage Example:
用法示例:
<a href="#" role="button">Button Link</a>
Screen Readers will read this element as “button” instead of “link”.
屏幕阅读器会将这个元素读为“按钮”,而不是“链接”。
There are four categories of roles:
角色分为四类:
- Abstract Roles 抽象角色
- Widget Roles 小部件角色
- Document Structure Roles 文件结构角色
- Landmark Roles 地标角色
有关HTML属性的更多信息: (More info about HTML attributes:)
有关HTML属性的更多信息 (More info about HTML attributes)
HTML elements can have attributes, which contain additional information about the element.
HTML元素可以具有属性,其中包含有关该元素的其他信息。
HTML attributes generally come in name-value pairs, and always go in the opening tag of an element. The attribute name says what type of information you’re providing about the element, and the attribute value is the actual information.
HTML属性通常以名称/值对的形式出现,并且总是放在元素的开始标记中。 属性名称说明您要提供的有关元素的信息类型,而属性值是实际信息。
For example, an anchor (<a>
) element in an HTML document creates links to other pages, or other parts of the page. You use the href
attribute in the opening <a>
tag to tell the browser where the link sends a user.
例如,HTML文档中的锚点( <a>
)元素创建到其他页面或页面其他部分的链接。 您可以在开始的<a>
标记中使用href
属性,以告诉浏览器该链接将用户发送到何处。
Here’s an example of a link that sends users to freeCodeCamp’s home page:
这是将用户发送到freeCodeCamp主页的链接的示例:
<a href="www.freecodecamp.org">Click here to go to freeCodeCamp!</a>
Notice that the attribute name (href
) and value (“www.freeCodeCamp.org”) are separated with an equals sign, and quotes surround the value.
请注意,属性名称( href
)和值(“ www.freeCodeCamp.org”)用等号分隔,并用引号引起来。
There are many different HTML attributes, but most of them only work on certain HTML elements. For example, the href
attribute won’t work if it’s placed in an opening <h1>
tag.
HTML有许多不同的属性,但是大多数属性仅适用于某些HTML元素。 例如,如果将href
属性放在开头的<h1>
标记中,则该属性将不起作用。
In the example above, the value supplied to the href
attribute could be any valid link. However, some attributes only have a set of valid options you can use, or values need to be in a specific format. The lang
attribute tells the browser the default language of the contents in an HTML element. The values for the lang
attribute should use standard language or country codes, such as en
for English, or it
for Italian.
在上面的示例中,提供给href
属性的值可以是任何有效链接。 但是,某些属性只有一组可以使用的有效选项,或者值必须采用特定格式。 lang
属性告诉浏览器HTML元素中内容的默认语言。 对于值lang
属性应当使用规范的语言或国家代码,如en
英语,或者it
意大利。
布尔属性 (Boolean Attributes)
Some HTML attributes don’t need a value because they only have one option. These are called Boolean attributes. The presence of the attribute in a tag will apply it to that HTML element. However, it’s okay to write out the attribute name and set it equal to the one option of the value. In this case, the value is usually the same as the attribute name.
一些HTML属性不需要值,因为它们只有一个选项。 这些称为布尔属性。 标签中属性的存在会将其应用于该HTML元素。 但是,可以写出属性名称并将其设置为等于值的一个选项。 在这种情况下,该值通常与属性名称相同。
For example, the <input>
element in a form can have a required
attribute. This requires users to fill out that item before they can submit the form.
例如,表单中的<input>
元素可以具有required
属性。 这就要求用户填写该项目,然后才能提交表单。
Here are examples that do the same thing:
以下是执行相同操作的示例:
<input type="text" required >
<input type="text" required="required" >
html属性和css属性