html div 属性
描述 (Description)
The div
is a generic block-level element. It doesn’t convey any meaning about its contents (unlike a p
element that signifies a paragraph, or an h1
or h2
element that would indicate a level 1 or level 2 heading, respectively); as such, it’s easy to customize it to your needs. The div
element is currently the most common method for identifying the structural sections of a document and for laying out a web page using CSS.
div
是通用的块级元素。 它没有传达任何有关其内容的含义(不同于表示段落的p
元素,或分别表示1级或2级标题的h1
或h2
元素); 这样,很容易根据您的需要对其进行自定义。 div
元素是当前用于识别文档的结构部分以及使用CSS布置网页的最常用方法。
Some developers perceive similarities between the p
and the div
elements, seeing them as being interchangeable, but this isn’t the case. The p
element offers more semantic information (“this is a paragraph of text, a small collection of thoughts that are grouped together; the next paragraph outlines some different thoughts”), while the div
element can be used to group almost any elements together. Indeed, it can contain almost any other element, unlike p
, which can only contain inline elements.
一些开发人员认为p
和div
元素之间存在相似之处,认为它们是可互换的,但事实并非如此。 p
元素提供了更多的语义信息(“这是一段文本,少量的思想被组合在一起;下一段概述了一些不同的思想”),而div
元素可用于将几乎所有元素组合在一起。 实际上,它可以包含几乎任何其他元素,不像p
,后者只能包含内联元素。
例 (Example)
The HTML below shows two div
s being used in conjunction with id
attributes to identify different sections of a web page:
以下HTML显示了两个div
与id
属性一起使用,以标识网页的不同部分:
<div id="main_navigation">
⋮
</div>
<div id="body_content">
<h1>Page heading</h1>
<p>Body content</p>
</div>
将此用于… (Use This For …)
The div
is an “anything-goes” element—it can contain any inline or block-level elements you choose, so it has no typical content.
div
是一个“万事通”元素-它可以包含您选择的任何内联或块级元素,因此没有典型的内容。
兼容性 (Compatibility)
Internet Explorer | Firefox | Safari | Opera | Chrome | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
5.5 | 6.0 | 7.0 | 8.0 | 1.0 | 1.5 | 2.0 | 3.0 | 3.5 | 1.3 | 2.0 | 3.1 | 4.0 | 9.2 | 9.5 | 10.0 | 2.0 |
Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full |
IE浏览器 | 火狐浏览器 | 苹果浏览器 | 歌剧 | Chrome | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
5.5 | 6.0 | 7.0 | 8.0 | 1.0 | 1.5 | 2.0 | 3.0 | 3.5 | 1.3 | 2.0 | 3.1 | 4.0 | 9.2 | 9.5 | 10.0 | 2.0 |
充分 | 充分 | 充分 | 充分 | 充分 | 充分 | 充分 | 充分 | 充分 | 充分 | 充分 | 充分 | 充分 | 充分 | 充分 | 充分 | 充分 |
This element has no compatibility issues. All the browsers listed support the div
element.
该元素没有兼容性问题。 列出的所有浏览器都支持div
元素。
html div 属性