此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。
<span>:內容區塊元素
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
<span> HTML 元素是一個通用的行級容器,用於包裹詞組內容,本身並不代表任何特定含義。它可用於為樣式目的(使用 class 或 id 屬性)對元素進行分組,或因它們共享屬性值(如 lang)而使用。僅在沒有其他語義元素適用時應使用 <span>。<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: #f00;
}
屬性
此元素僅包括全域屬性。
範例
>範例 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;
}
結果
[フレーム]
技術摘要
規範
| Specification |
|---|
| HTML> # the-span-element> |
瀏覽器相容性
Loading...
參見
- HTML
<div>元素