CSS 平級和兒子級樣式寫法示例

字號:


    input:checked+ol:這個是講當inoput 擁有了checked后它平級的OL擁有的樣式。
    input:checked+ol>li:中的大于是指當inoput 擁有了checked后它平級的OL下面兒子輩的li的樣式,孫子輩的不繼承。
    Html代碼
    代碼如下:
    <!DOCTYPE html>
    <html lang="zh-cn">
    <head>
    <meta charset="utf-8" />
    <title>用戶界面(UI)元素狀態(tài)偽類選擇符 E:checked_CSS參考手冊_web前端開發(fā)參考手冊系列</title>
    <style type="text/css">
    input[type=radio]:checked + span{background:blue;}
    input[type=radio]:checked + span:after{content:" 我被選中了";}
    input[type=checkbox]:checked + span{background:#f00;}
    input[type=checkbox]:checked + span:before{content:" 我被選中了";}
    div.classFather > div.classSon div.classSon{
    background-color: lightgray;
    line-height: 40px;
    }
    div.classFather > div.classSon > div.classSonS > div.classSonC {
    background-color: lightgray;
    line-height: 40px;
    }
    </style>
    </head>
    <body>
    <form method="post" action="#">
    <fieldset>
    <legend>選中下面的項試試</legend>
    <ul>
    <li><label><input type="radio" name="colour-group" value="0" /><span>藍色</span></label></li>
    <li><label><input type="radio" name="colour-group" value="1" /><span>紅色</span></label></li>
    <li><label><input type="radio" name="colour-group" value="2" /><span>黑色</span></label></li>
    </ul>
    </fieldset>
    <fieldset>
    <legend>選中下面的項試試</legend>
    <ul>
    <li><label><input type="checkbox" name="colour-group2" value="0" /><span>藍色</span></label></li>
    <li><label><input type="checkbox" name="colour-group2" value="1" /><span>紅色</span></label></li>
    <li><label><input type="checkbox" name="colour-group2" value="2" /><span>黑色</span></label></li>
    </ul>
    </fieldset>
    <fieldset>
    <legend>子節(jié)點樣式</legend>
    <div>
    <div>孩子
    <div>孫子
    <div>重孫子</div>
    </div>
    </div>
    <div>孩子
    <div>孫子
    <div>重孫子</div>
    </div>
    </div>
    </div>
    </fieldset>
    </form>
    </body>
    </html>