<span>:內容 span 元素
<span> HTML 元素是一個通用的行內容器,用於放置短語內容,它本身不代表任何特定內容。它可以用於將元素分組以進行樣式設定(使用 class 或 id 屬性),或者因為它共享屬性值(例如 lang)。只有在沒有其他語義元素合適時才應使用它。<span> 元素非常類似於 <div> 元素,但 <div> 是一個塊級元素,而 <span> 是一個行內元素。
試一試
<p>
Add the <span class="ingredient">basil</span>,
<span class="ingredient">pine nuts</span> and
<span class="ingredient">garlic</span> to a blender and blend into a paste.
</p>
<p>
Gradually add the <span class="ingredient">olive oil</span> while running the
blender slowly.
</p>
span.ingredient {
color: red;
}
屬性
此元素僅包含全域性屬性。
示例
示例 1
HTML
html
<p><span>Some text</span></p>
結果
示例 2
HTML
html
<li>
<span>
<a href="portfolio.html" target="_blank">See my portfolio</a>
</span>
</li>
CSS
css
li span {
background: gold;
}
結果
技術摘要
規範
| 規範 |
|---|
| HTML # the-span-element |
瀏覽器相容性
載入中…
另見
- HTML
<div>元素