Skip to main content

CSS 元素选择器 Type selectors

元素选择器 Type selector:按照给定的节点名称,选择所有匹配的元素。使用元素的名称

  • 语法:elementname
  • 例子:input 匹配任何 <input> 元素。
元素选择器 Type selector
/* All <a> elements. */
a {
color: red;
}

CSS 元素选择器 (也称为类型选择器) 通过 node 节点名称匹配元素。因此,在单独使用时,寻找特定类型的元素时,元素选择器都会匹配该文档中所有此类型的元素。

语法:元素 { 样式声明 }

在 CSS3 中,元素选择器 可以和命名空间 @namespace组合使用:

  • ns|h1 -会匹配 ns 命名空间下的所有 <h1> 元素
  • *|h1 - 会匹配所有命名空间下的所有 <h1> 元素
  • |h1 - 会匹配所有没有命名空间的 <h1> 元素
<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>
http://localhost:3000/css-type-selectors.html
Here's a span with some text.

Here's a p with some text.

Here's a span with more text.