CSS选择器

CSS选择器的简单介绍


提示:以下是本篇文章正文内容,下面案例可供参考

一、compound selector(复合选择器)

A compound selector is a sequence of simple selectors that are not separated by a combinator, and represents a set of simultaneous conditions on a single element.
As whitespace represents the descendant combinator, no whitespace is allowed between the simple selectors in a compound selector.
If it contains a type selector or universal selector, that selector must come first in the sequence. Only one type selector or universal selector is allowed in the sequence.

复合选择器是一系列不被组合子分隔的简单选择器,表示单个元素上的一组同时条件。
由于空白表示子代组合子,所以在复合选择器中的简单选择器之间不允许有空白。
如果它包含类型选择器或通用选择器,则该选择器必须位于序列的第一位。序列中只允许有一个类型选择器或通用选择器。

        .frist.one{
            font-family: 楷体;
            color: rgb(4, 57, 32);
        }

        a:link{
            color: rgb(176, 0, 0); text-decoration: none;
        }
        a:hover{
             color: green; 
            }
        a:active{
            color: darkslategrey;
        }
        a:visited{
            color: fuchsia;
        }

不仅可以设置多个指定字符存在的class中(但指定的字符中间不可有任何分隔符),也可指定某个元素因为用户行为而改变的样式。

在这里插入图片描述
浏览过之后:
在这里插入图片描述
激活后:
在这里插入图片描述
悬浮后改变:

在这里插入图片描述

注意:
伪类中 ::link 要设置在 :hover 之前,不然会使 :hover 修改的样式失效。

二、sibling combinator (后代选择器(或称作子孙选择器))

            main { border: 1px solid blue; }
            /* 后代选择器(或称作子孙选择器) */
            main p { border: 1px solid green; }
            /* 亲子选择器 */
            main>p { background-color: #dfdfdf; }

            #first-paragraph {text-align: center; }

            /* 相邻的兄弟选择器 ( next-sibling combinator ) */
            #first-paragraph + * { border: 1px solid red; }
            /* 后面的兄弟选择器 ( subsequent-sibling combinator ) */
            #first-paragraph ~ * { margin: 10px; }
  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值