Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 979695 of <span>

  • 版本网址缩略名: Web/HTML/Element/span
  • 版本标题: <span>
  • 版本 id: 979695
  • 创建于:
  • 创建者: King.
  • 是否是当前版本?
  • 评论
标签: 

修订内容

概要

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

属性

该元素仅包含 全局属性

例 1

<p><span>Some text</span></p>

结果

Some text

 

例 2

<li><span>
    <a href="portfolio.html" target="_blank">See my portfolio</a>
</span></li>

CSS:

li span {
    background: gold;
}

结果

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', 'text-level-semantics.html#the-span-element', '<span>')}} {{Spec2('HTML WHATWG')}}  
{{SpecName('HTML5 W3C', 'text-level-semantics.html#the-span-element', '<span>')}} {{Spec2('HTML5 W3C')}} The DOM interface is now {{domxref("HTMLSpanElement")}}.
{{SpecName('HTML4.01', 'struct/global.html#edef-SPAN', '<span>')}} {{Spec2('HTML4.01')}}  

浏览器兼容性

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}

 

参见

  • HTML {{HTMLElement("div")}} 元素
{{HTMLRef}}

修订版来源

<h2 id="Summary" name="Summary">概要</h2>

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

<ul class="htmlelt">
 <li><dfn><a href="/en-US/docs/HTML/Content_categories" title="HTML/Content_categories">Content categories</a></dfn> <a href="/en-US/docs/HTML/Content_categories#Flow_content" title="HTML/Content categories#Flow content">Flow content</a>, <a href="/en-US/docs/HTML/Content_categories#Phrasing_content" title="HTML/Content categories#Phrasing content">phrasing content</a>.</li>
 <li><dfn>Permitted content</dfn><a href="/en-US/docs/HTML/Content_categories#Phrasing_content" title="HTML/Content categories#Phrasing content">Phrasing content</a></li>
 <li><dfn>Tag omission</dfn> {{no_tag_omission}}</li>
 <li><dfn>Permitted parent elements</dfn>Any element that accepts <a href="/en-US/docs/HTML/Content_categories#Phrasing_content" title="https://developer.mozilla.org/en-US/docs/HTML/Content_categories#Phrasing_content">phrasing content</a>, or any element that accepts <a href="/en-US/docs/HTML/Content_categories#Flow_content" title="https://developer.mozilla.org/en-US/docs/HTML/Content_categories#Flow_content">flow content</a>.</li>
 <li><dfn>DOM interface</dfn> {{domxref("HTMLSpanElement")}} (before HTML 5, the interface was {{domxref("HTMLElement")}}</li>
</ul>

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

<p><span style="line-height:21px">该元素仅包含&nbsp;</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">
&lt;p&gt;&lt;span&gt;Some text&lt;/span&gt;&lt;/p&gt;</pre>

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

<p><span>Some text</span></p>

<p>&nbsp;</p>

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

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

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

<div class="note">
<p name="Result">li span {<br />
 &nbsp;&nbsp;&nbsp; background: gold;<br />
 }</p>
</div>

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

<ul>
 <li><span style="background:gold">&nbsp;&nbsp;&nbsp; <a href="portfolio.html" target="_blank">See my portfolio</a></span></li>
</ul>

<h2 id="Specifications"><span>Specifications</span></h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</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>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5 W3C', 'text-level-semantics.html#the-span-element', '&lt;span&gt;')}}</td>
   <td>{{Spec2('HTML5 W3C')}}</td>
   <td>The DOM interface is now {{domxref("HTMLSpanElement")}}.</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML4.01', 'struct/global.html#edef-SPAN', '&lt;span&gt;')}}</td>
   <td>{{Spec2('HTML4.01')}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>

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

<p>{{ CompatibilityTable() }}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{ CompatVersionUnknown() }}</td>
   <td>{{ CompatVersionUnknown() }}</td>
   <td>{{ CompatVersionUnknown() }}</td>
   <td>{{ CompatVersionUnknown() }}</td>
   <td>{{ CompatVersionUnknown() }}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE&nbsp;Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{ CompatVersionUnknown() }}</td>
   <td>{{ CompatVersionUnknown() }}</td>
   <td>{{ CompatVersionUnknown() }}</td>
   <td>{{ CompatVersionUnknown() }}</td>
   <td>{{ CompatVersionUnknown() }}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also" name="See_also">&nbsp;</h2>

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

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

<div>{{HTMLRef}}</div>
恢复到这个版本