HTML 中 DIV 元素的有效属性是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2185519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are valid attributes for the DIV element in HTML?
提问by JasonK
回答by Sinan ünür
See W3C specs:
请参阅W3C 规范:
id
,class
(document-wide identifiers)lang
(language information),dir
(text direction)title
(element title)style
(inline style information)align
(alignment)onclick
,ondblclick
,onmousedown
,onmouseup
,onmouseover
,onmousemove
,onmouseout
,onkeypress
,onkeydown
,onkeyup
id
,class
(文档范围的标识符)lang
(语言信息),dir
(文本方向)title
(元素标题)style
(内联样式信息)align
(结盟)onclick
,ondblclick
,onmousedown
,onmouseup
,onmouseover
,onmousemove
,onmouseout
,onkeypress
,onkeydown
,onkeyup
for
is for label
and specifies the id
attribute of the input element to which the label applies.
for
用于label
并指定id
标签适用的输入元素的属性。
See also the HTML5 specs:
另请参阅HTML5 规范:
The
div
element has no special meaning at all. It represents its children. It can be used with theclass
,lang
, andtitle
attributes to mark up semantics common to a group of consecutive elements.Note:Authors are strongly encouraged to view the
div
element as an element of last resort, for when no other element is suitable. Use of more appropriate elements instead of thediv
element leads to better accessibility for readers and easier maintainability for authors.
该
div
元素根本没有特殊含义。它代表它的孩子。它可以与被使用class
,lang
和title
属性语义共同标记到一组连续的元素。注意:强烈鼓励作者将该
div
元素视为最后的元素,因为当没有其他元素适合时。使用更合适的元素而不是div
元素会为读者带来更好的可访问性,并为作者带来更容易的可维护性。
回答by kapa
With HTML5, besides using the global attributeswhich can be used on any element, you can also define your own attributes using the data-
attributes.
在 HTML5 中,除了使用可用于任何元素的全局属性外,您还可以使用data-
attributes定义自己的属性。
<div class="marvellous" data-for="xy" data-another-attribute="nothing"></div>
All you have to do is use the HTML5 doctype (<!DOCTYPE html>
) and your page will be valid. This doctype works fine even in older browsers.
您所要做的就是使用 HTML5 doctype ( <!DOCTYPE html>
) 并且您的页面将有效。即使在较旧的浏览器中,此文档类型也能正常工作。
回答by Ajay Gupta
contenteditable attribute also helpful and rarely used.
contenteditable 属性也很有帮助但很少使用。
<div contenteditable="true">Using this on runtime content can changed.</div>
This attribute is provide a way to use this like a Normal textbox. but text changed on browser side is not saved in coding.
该属性提供了一种像普通文本框一样使用它的方法。但是在浏览器端更改的文本不会保存在编码中。
回答by Guillaume Flandre
A list of attributes is available here: https://www.w3schools.com/tags/tag_div.asp
属性列表可在此处获得:https: //www.w3schools.com/tags/tag_div.asp
- class
- dir
- id
- lang
- style
- title
- xml:lang
- 班级
- 目录
- ID
- 朗
- 风格
- 标题
- xml:lang
Plus all the event attributes:
加上所有事件属性:
- onclick
- ondblclick
- onmousedown
- onmousemove
- onmouseout
- onmouseover
- onmouseup
- onkeydown
- onkeypress
- onkeyup
- 点击
- ondblclick
- 鼠标按下
- 鼠标移动
- 鼠标移出
- 鼠标悬停
- 上鼠标
- 按键按下
- 按键
- 上键