此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。

View in English Always switch to English

型態選擇器

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月⁩.

CSS 型態選擇器依照節點名稱選取匹配的元素。換句話說,此選擇器選取在文件內所有指定該型態的元素。

css
/* 全部的 <a> 元素。*/
a {
  color: red;
}

語法

css
element { style properties }

範例

CSS

css
span {
  background-color: skyblue;
}

HTML

html
<span>Here's a span with some text.</span>
<p>Here's a p with some text.</p>
<span>Here's a span with more text.</span>

結果

規範

Specification
Selectors Level 4
# type-selectors

瀏覽器相容性