CSS伪类

1.连接伪类(注意顺序)数据库

  • Link
  • Visited
  • Hover
  • Active

Tip:一个冒号(:)表示伪类,两个冒号(::)表示CSS3新增的伪元素。spa

2. :focus伪类 和 :target伪类code

实例1:input:focus {border:1px solid blue;}orm

实例2: <h2 id="more_info">This is the information you are looking for.</h2>
      #more_info:target {background:#eee}ip

3.结构化伪类get

3.1 :first-child和:last-childinput

格式:e:first-childit

         e:last-childio

实例:ol.results li:first-child{color:blue;}ast

3.2 :nth-child

格式:e:nth-child(n)

实例:li:nth-child(3)

说明:e表示元素名,n表示一个数值(也能够使用odd或even)

4.伪元素

4.1 ::first-letter伪元素

格式:e::first-letter
示例:p::first-letter {font-size:300%;}

提示:若是不用伪元素建立这个首字符放大效果,必须手工给该字母加上标签,
而后再为该标签应用样式。而伪元素其实是替咱们添加了无形的标签。

4.2 ::first-line伪元素

格式:e::first-line
示例:p::first-line {font-variant:small-caps;}
说明:选中文本段落(通常状况下是段落)的第一行。

4.3 ::before和::after伪元素

格式:
e::before
e::after
示例:
对标记:
<p class="age">25</p>
添加以下样式:
p.age::before {content:"Age: ";}
p.age::after {content:" years.";}
会获得以下结果:
Age: 25 years.

提示:若是标签中的内容是经过数据库查询生成的结果,那么用这种技巧再合适不过了。由于全部结果都是数字,使用这两个伪元素能够在把数字呈现给用户时,加上说明性文字。

相关文章
相关标签/搜索