aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/html/element/span/index.html
blob: 4470ad4e800a53b6e644749a8f975beb3e405a86 (plain)
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
---
title: <span>
slug: Web/HTML/Element/span
tags:
  - HTML
  - span
  - 元素
  - 流内容
  - 行内元素
translation_of: Web/HTML/Element/span
---
<div>{{HTMLRef}}</div>

<p><strong>HTML <code>&lt;span&gt;</code> </strong>元素是短语内容的通用行内容器,并没有任何特殊语义。可以使用它来编组元素以达到某种样式意图(通过使用类或者Id属性),或者这些元素有着共同的属性,比如<strong>lang</strong>。应该在没有其他合适的语义元素时才使用它。<code>&lt;span&gt;</code> 与 {{HTMLElement("div")}} 元素很相似,但 {{HTMLElement("div")}} 是一个 <a href="/en-US/docs/HTML/Block-level_elements">块元素</a><code>&lt;span&gt;</code> 则是 <a href="/en-US/docs/HTML/Inline_elements"> 行内元素 </a>.</p>

<div>{{EmbedInteractiveExample("pages/tabbed/span.html", "tabbed-shorter")}}</div>

<div 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.</div>

<ul class="htmlelt">
 <li><dfn><a href="/en-US/docs/HTML/Content_categories" title="HTML/Content_categories">内容分类</a></dfn> <a href="/en-US/docs/HTML/Content_categories#Flow_content" title="HTML/Content categories#Flow content">流内容</a>, <a href="/en-US/docs/HTML/Content_categories#Phrasing_content" title="HTML/Content categories#Phrasing content">表述内容</a>.</li>
 <li><dfn>允许的内容</dfn><a href="/zh-CN/docs/Web/Guide/HTML/Content_categories#Phrasing_content">短语元素</a></li>
 <li><dfn>标签省略</dfn> 不允许,开始标签和结束标签都不能省略。</li>
 <li><dfn>允许的父元素</dfn>任意可以包含 <a href="/en-US/docs/HTML/Content_categories#Phrasing_content" title="https://developer.mozilla.org/en-US/docs/HTML/Content_categories#Phrasing_content">表述内容</a> 或 <a href="/en-US/docs/HTML/Content_categories#Flow_content" title="https://developer.mozilla.org/en-US/docs/HTML/Content_categories#Flow_content">流内容</a> 的元素。</li>
 <li><dfn>DOM 接口</dfn>{{domxref("HTMLSpanElement")}} (在 {{glossary("HTML5")}}, 之前是 {{domxref("HTMLElement")}})</li>
</ul>

<h2 id="Attributes" name="Attributes">属性</h2>

<p><span style="line-height: 21px;">该元素仅包含 </span><a href="https://developer.mozilla.org/en-US/docs/HTML/Global_attributes" style="line-height: 21px;" title="HTML/Global attributes">全局属性</a></p>

<h2 id="Example1" name="Example1">例 1</h2>

<pre class="brush:html;gutter:false notranslate">&lt;p&gt;&lt;span&gt;一些文字&lt;/span&gt;&lt;/p&gt;</pre>

<h3 id="Result1" name="Result1">结果</h3>

<p>{{EmbedLiveSample('Example1')}}</p>

<h2 id="Example2" name="Example2">例 2</h2>

<pre class="brush:html;gutter:false notranslate">&lt;li&gt;&lt;span&gt;
    &lt;a href="portfolio.html" target="_blank"&gt;See my portfolio&lt;/a&gt;
&lt;/span&gt;&lt;/li&gt;
</pre>

<h3 id="CSS">CSS</h3>

<pre class="brush:css notranslate; notranslate"><code>li span {
  background: gold;
 }</code></pre>

<h3 id="Result2" name="Result2">结果</h3>

<p>{{EmbedLiveSample('Example2')}}</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', 'text-level-semantics.html#the-span-element', '&lt;span&gt;')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5 W3C', 'text-level-semantics.html#the-span-element', '&lt;span&gt;')}}</td>
   <td>{{Spec2('HTML5 W3C')}}</td>
   <td>
    <p>{{domxref("HTMLSpanElement")}} (在 {{glossary("HTML5")}}, 之前是 {{domxref("HTMLElement")}})</p>
   </td>
  </tr>
  <tr>
   <td>{{SpecName('HTML4.01', 'struct/global.html#edef-SPAN', '&lt;span&gt;')}}</td>
   <td>{{Spec2('HTML4.01')}}</td>
   <td></td>
  </tr>
 </tbody>
</table>

<h2 id="See_also" name="See_also">浏览器兼容性</h2>

<p>{{Compat("html.elements.span")}}</p>

<h2 id="See_also" name="See_also">参见</h2>

<ul>
 <li>HTML {{HTMLElement("div")}} 元素</li>
</ul>