HTML
<span>
element
is a generic inline container for phrasing content, which does not inherently represent anything. It can be used to group elements for styling purposes (using the
class
or
id
attributes), or because they share attribute values, such as
lang
.
It should be used only when no other semantic element is appropriate.
<span>
is very much like a
<div>
element, but
<div>
是
block-level element
whereas a
<span>
是
inline element
.
| 内容类别 | 流内容 , 措词内容 . |
|---|---|
| 准许内容 | 措词内容 . |
| Tag omission | None, both the starting and ending tag are mandatory. |
| Permitted parents | Any element that accepts 措词内容 , or any element that accepts flow content . |
| Implicit ARIA role | 无对应角色 |
| Permitted ARIA roles | 任何 |
| DOM 接口 |
HTMLSpanElement
(before
HTML5
, the interface was
HTMLElement
)
|
此元素只包括 全局属性 .
<p><span>Some text</span></p>
<li><span>
<a href="portfolio.html">See my portfolio</a>
</span></li>
li span {
background: gold;
}
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | Android webview | Chrome for Android | Firefox for Android | Opera for Android | Safari on iOS | Samsung Internet | |
span
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 1 | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 4 | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
完整支持
<div>
element