1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
---
title: <div>:内容划分元素
slug: Web/HTML/Element/div
tags:
- Element
- HTML
- Layout
- Reference
- Web
- 元素
- 参考
- 布局
translation_of: Web/HTML/Element/div
---
<div>{{HTMLRef}}</div>
<p><strong><a href="/zh-CN/docs/Web/HTML">HTML</a> <code><div></code> 元素</strong> (或 <em>HTML 文档分区元素</em>) 是一个通用型的流内容容器,在不使用{{glossary("CSS")}}的情况下,其对内容或布局没有任何影响。</p>
<div>{{EmbedInteractiveExample("pages/tabbed/div.html","tabbed-standard")}}</div>
<p class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples </a> and send us a pull request.</p>
<p>作为一个 “纯粹的” 容器,<code><div></code> 元素在语义上不表示任何特定类型的内容。然而,其可以将内容分组,从而可以使用{{htmlattrxref("class")}}或是{{htmlattrxref("id")}}属性方便的定义内容的格式,也可以在一段文档中划分标记出使用另一种语言书写的内容(使用{{htmlattrxref("lang")}} 属性)等等。</p>
<table class="properties">
<tbody>
<tr>
<th scope="row"><a href="/zh-CN/docs/Web/Guide/HTML/Content_categories">所属内容分类</a>(<a href="/en-US/docs/Web/HTML/Content_categories">Content categories</a>)</th>
<td><a href="/en-US/docs/Web/HTML/Content_categories#Flow_content">Flow content</a>, palpable content.</td>
</tr>
<tr>
<th scope="row">允许的子元素</th>
<td><a href="/en-US/docs/Web/HTML/Content_categories#Flow_content">Flow content</a>.<br>
Or (in {{glossary("WHATWG")}} HTML): If the parent is a {{HTMLElement("dl")}} element: one or more {{HTMLElement("dt")}} elements followed by one or more {{HTMLElement("dd")}} elements, optionally intermixed with {{HTMLElement("script")}} and {{HTMLElement("template")}} elements.</td>
</tr>
<tr>
<th scope="row">Tag omission</th>
<td>{{no_tag_omission}}</td>
</tr>
<tr>
<th scope="row">允许的父元素</th>
<td>Any element that accepts <a href="/en-US/docs/Web/HTML/Content_categories#Flow_content">flow content</a>.<br>
Or (in {{glossary("WHATWG")}} HTML): {{HTMLElement("dl")}} element.</td>
</tr>
<tr>
<th scope="row">Permitted ARIA roles</th>
<td>Any</td>
</tr>
<tr>
<th scope="row">所使用的 DOM API 接口</th>
<td>{{domxref("HTMLDivElement")}}</td>
</tr>
</tbody>
</table>
<h2 id="属性">属性</h2>
<p>该元素支持所有<a href="/zh-CN/docs/Web/HTML/Global_attributes">全局属性</a>。</p>
<div class="blockIndicator note">
<p><strong>注意:</strong> <code>align</code> 属性已废弃;不要再使用它了。你应当使用 <a href="/en-US/docs/Web/CSS/CSS_Grid_Layout">CSS Grid</a> 或 <a href="/en-US/docs/Learn/CSS/CSS_layout/Flexbox">CSS Flexbox</a> 来对齐、定位页面上的 <code><div></code> 元素。</p>
</div>
<h2 id="使用备注">使用备注</h2>
<ul>
<li><code><div></code> 元素应当仅在没有任何其它语义元素(比如 {{HTMLElement("article")}} 或 {{HTMLElement("nav")}})可用时使用。</li>
</ul>
<h2 id="示例">示例</h2>
<h3 id="一个简单的例子">一个简单的例子</h3>
<pre class="brush: html"><div>
<p>这里可以是任何内容,比如 &lt;p&gt;,
&lt;table&gt;,一切由你作主!</p>
</div>
</pre>
<p>结果看起来像这样:</p>
<div>这里可以是任何内容,比如 <p>, <table>,一切由你作主!</div>
<p>实例:</p>
<p>{{EmbedLiveSample("A_simple_example", 650, 60)}}</p>
<h3 id="样式实例">样式实例</h3>
<p>本例使用 CSS 将样式应用于<div>,从而创建一个阴影框。注意使用<div>上的 {{htmlattrxref("class")}}属性将名为 “shadowbox” 的样式应用于元素。</p>
<h4 id="HTML">HTML</h4>
<pre class="brush: html"><div class="shadowbox">
<p>Here's a very interesting note displayed in a
lovely shadowed box.</p>
</div></pre>
<h4 id="CSS">CSS</h4>
<pre class="brush: css">.shadowbox {
width: 15em;
border: 1px solid #333;
box-shadow: 8px 8px 5px #444;
padding: 8px 12px;
background-image: linear-gradient(180deg, #fff, #ddd 40%, #ccc);
}</pre>
<h4 id="结果">结果</h4>
<p>{{EmbedLiveSample("A_styled_example", 650, 120)}}</p>
<h2 id="规范">规范</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">规范</th>
<th scope="col">状态</th>
<th scope="col">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('HTML WHATWG', 'grouping-content.html#the-div-element', '<div>')}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
<td>No changes since the latest snapshot</td>
</tr>
<tr>
<td>{{SpecName('HTML5 W3C', 'grouping-content.html#the-div-element', '<div>')}}</td>
<td>{{Spec2('HTML5 W3C')}}</td>
<td>Obsoleted <code>align</code></td>
</tr>
<tr>
<td>{{SpecName('HTML4.01', 'struct/global.html#h-7.5.4', '<div>')}}</td>
<td>{{Spec2('HTML4.01')}}</td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{Compat("html.elements.div")}}</p>
<h2 id="参见">参见</h2>
<ul>
<li>Semantic sectioning elements: {{HTMLElement("section")}}, {{HTMLElement("article")}}, {{HTMLElement("nav")}}, {{HTMLElement("header")}}, {{HTMLElement("footer")}}</li>
<li>{{HTMLElement("span")}} element for styling of phrasing content</li>
</ul>
|