CSS选择器

2018-02-27  本文已影响0人  yangchaojun

简单选择器

1.通配选择器

*{ 
    color: red;
}
/*不推荐使用通配选择器,因为它是[性能最低的一个CSS选择器*/

2.标签选择器

p{
    color: red;
    font-size: 15px;
}

3.id选择器

#id{
    color: red;
}

4.类选择器

.content{
    color: red;
}

复杂选择器

属性选择器(CSS 属性选择器通过已经存在的属性名或属性值匹配元素。)
a {
  color: blue;
}

/* 内部链接,以“#”为开头 */
a[href^="#"] {
  background-color: gold;
}

/* 在URL中任何地方包含“example” */
a[href*="example"] {
  background-color: silver;
}

/* Links with "insensitive" anywhere in the URL,
   regardless of capitalization */
a[href*="insensitive" i] {
  color: cyan;
}

/*以“.org”结尾 */
a[href$=".org"] {
  color: red;
}
<ul>
  <li><a href="#internal">Internal link</a></li>
  <li><a href="http://example.com">Example link</a></li>
  <li><a href="#InSensitive">Insensitive internal link</a></li>
  <li><a href="http://example.org">Example org link</a></li>
</ul>
伪类选择器

下面是几个常用的例子:

选择器组合
上一篇 下一篇

猜你喜欢

热点阅读