再探 css

一、伪类

1. link

普通的链接

a:link {
    color: yellowgreen;
}

2. visited

访问过的链接,只能设置颜色

a:visited {
    color: yellowgreen;
}

3. hover

鼠标移入状态

a:hover {
    color: yellowgreen;
}

4. active

鼠标点击

a:active {
    color: yellowgreen;
}

5. focus

获取焦点

input:focus {
    background-color: orange;
}

6. 文字内容选中

(1) 火狐浏览器

-moz-selection

p::-moz-selection {
    background-color: orange;
}

(2) 其他浏览器

selection

p::selection {
    background-color: orange;
}

二、伪元素

1. 首字

p:first-letter {
    color: red;
    font-size: 20px;
}

2. 首行

p:first-line {
    background-color: red;
}

3. 最前面before

p:before {
    content: "最前面";
    color: red;
}

4. 最后面after

p:after {
    content: "最后面";
    color: red;
}

4. 属性选择器

(1) 含有title属性

p[title] {
    background-color: red;
}

 (2) 含有属性值

p[title="hello"] {
    background-color: red;
}

(3) 属性值以ab开头

p[title^="ab"] {
    background-color: red;
}

(4) 属性值以ab结尾

p[title$="ab"] {
    background-color: red;
}

 (5) 属性值包含c

p[title*="c"] {
    background-color: red;
}

(6) 选中span后的紧挨着的p元素

span+p {
    background-color: red;
}

(7) 选中span后的所有的p元素

span~p {
    background-color: red;
}

(8) 否定

p:not(.hello) {
    background-color: red;
}

(9) 其他

名字作用
first-child选中第一个子元素
last-child选中最后一个子元素
nth-child(num)选中任意num位置,可以指定num,odd表示奇数,even表示偶数
first-of-type选中第一个元素
last-of-type选中最后一个元素
nth-of-type(num)选中任意num位置,可以指定num,odd表示奇数,even表示偶数

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值