美文网首页
CSS选择器

CSS选择器

作者: 大步迈 | 来源:发表于2016-09-02 14:17 被阅读4次

    普通选择器  

      直接的标签就可以作为标签

    类选择器和ID选择器

    通配符选择器

    属性选择器[disabled][type=button]

    <h2 class="title sports">标题</h2>

    <p class="sports">内容</p>

    [class~=sports]{color=blue;} 同时选中 

    伪类选择器

    :nth-child(3n+1)(even)(odd)  nth-last-child()

    only-child  first/last-of-type(even/odd)

    伪元素选择器

    ::first-letter /line {第一个字符设置格式}

    ::before   ::after  ::selection   被选中样式的样式

    组合选择器

    后代选择器   .main  h2 {}

    子选择器  .main>h2{}

    兄弟选择器  相邻h2+p{}   通用h2~p{ }

    选择器分组

    继承

    CSS优先级

    计算方法

    a=行内元素  权重:1000

    b=ID选择器  权重:100

    c=类、伪类、和选择器的数量 权重:10

    d=标签选择器和伪类选择器的数量  权重:1

    CSS层叠

    相同的属性覆盖

    优先级   后面覆盖前面

    不同的属性会合并

    CSS改变优先级

    改变先后顺序

    提升选择器优先级

    !important

    相关文章

      网友评论

          本文标题:CSS选择器

          本文链接:https://www.haomeiwen.com/subject/coghettx.html