diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/html/element/div | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/html/element/div')
-rw-r--r-- | files/zh-cn/web/html/element/div/index.html | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/files/zh-cn/web/html/element/div/index.html b/files/zh-cn/web/html/element/div/index.html new file mode 100644 index 0000000000..15f608528b --- /dev/null +++ b/files/zh-cn/web/html/element/div/index.html @@ -0,0 +1,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> |