zoukankan      html  css  js  c++  java
  • css 属性选择器笔记

    1、基本选择器:

    eg:

    *{margin:0;padding:0}
    
    p{color:black}
    
    .content{background:red;}
    
    #intro{padding-left:2em;}

    2、多元素组合选择器

    div p { color:#f00; }
    
    #nav li { display:inline; }
    
    #nav a { font-weight:bold; }
    
    div > strong { color:#f00; }
    
    h2 + p { color:#f00; }

    三、CSS 2.1 属性选择器

    eg:

    p[title] { color:#f00; }
    
    div[class=error] { color:#f00; }
    
    td[headers~=col1] { color:#f00; }
    
    p[lang|=en] { color:#f00; }
    
    blockquote[class=quote][cite] { color:#f00; }

    四、CSS 2.1中的伪类

    eg

    p:first-child { font-style:italic; }
    
    input[type=text]:focus { color:#000; background:#ffe; }
    
    input[type=text]:focus:hover { background:#fff; }
    
    q:lang(sv) { quotes: "201D" "201D" "2019" "2019"; }

    五、 CSS 2.1中的伪元素

    eg:

    p:first-line { font-weight:bold; color;#600; }
    
    .preamble:first-letter { font-size:1.5em; font-weight:bold; }
    
    .cbb:before { content:""; display:block; height:17px; width:18px; }
    
    background:url(top.png) no-repeat 0 0; margin:0 0 0 -18px; }
    
    a:link:after { content: " (" attr(href) ") "; }

    六、CSS 3的同级元素通用选择器

    eg:

    p ~ ul { background:#ff0; }

    七、CSS 3 属性选择器

    eg:

    div[id^="nav"] { background:#ff0; }

    八、CSS 3中与用户界面有关的伪类

    input[type="text"]:disabled { background:#ddd; }

    九、CSS 3中的结构性伪类

     eg

    p:nth-child(3) { color:#f00; }
    
    p:nth-child(odd) { color:#f00; }
    
    p:nth-child(even) { color:#f00; }
    
    p:nth-child(3n+0) { color:#f00; }
    
    p:nth-child(3n) { color:#f00; }
    
    tr:nth-child(2n+11) { background:#ff0; }
    
    tr:nth-last-child(2) { background:#ff0; }
    
    p:last-child { background:#ff0; }
    
    p:only-child { background:#ff0; }
    
    p:empty { background:#ff0; }

    十、CSS 3的反选伪类

     

    十一、CSS 3中的 :target 伪类

    转自:http://www.ruanyifeng.com/blog/2009/03/css_selectors.html

    在写css属性选择器时注意特殊性的值得权重

  • 相关阅读:
    java 学习帮助
    权限
    ftp mybatis
    注解
    hadoop english
    userDao
    发布订阅模式 和委托
    webservice
    rabbitMq视频教程
    blog url.txt
  • 原文地址:https://www.cnblogs.com/feilu2016/p/7115988.html
Copyright © 2011-2022 走看看