Sélecteur de co...SE CONNECTER

Sélecteur de combinaison du didacticiel CSS Basics

Sélecteur multi-éléments

  • Description : Ajoutez le même style à plusieurs éléments, plusieurs sélecteurs sont séparés par des virgules ",".

  • Exemple : h1,p,div,body{color:red;}

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php.cn</title>
    <style type="text/css">
    h1,p,.NO1{
         color:red;
         background-color:#88ff66;
     }
    </style>
    </head>
    <body>
        <h1>习近平心中的互联网</h1>
        <p>互联网是20世纪最伟大的发明,它正在将人类“一网打尽”,人们在不知不觉中已经融入了互联网生态,互联网让世界变成了“鸡犬之声相闻”的地球村。</p>
        <div class="NO1">习近平指出:“互联网已经融入社会生活方方面面,深刻改变了人们的生产和生活方式。”</div>
    </body>
</html>

< Description  : Ajoutez des styles à un élément descendant d'une balise. Les sélecteurs sont séparés par des "espaces".


Exemple : div .title{ color:red;}

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php.cn</title>
    <style type="text/css">
        div h1.title{background-color:yellow;}
        div p.paragraph{background-color:#88ff88;}
    </style>
    </head>
    <body>
        <div>
        <h1 class="title">习近平心中的互联网</h1>
        <p class="paragraph">互联网是20世纪最伟大的发明,它正在将人类“一网打尽”,人们在不知不觉中已经融入了互联网生态,互联网让世界变成了“鸡犬之声相闻”的地球村。</p>
        </div>
    </body>
</html>
  • Sélecteur d'élément enfant

Description : Ajoutez des styles aux éléments enfants d'un élément.


Exemple : div > h1.title{color:red;}

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php.cn</title>
    <style type="text/css">
        div>.title{background-color:#88ff88;}
        div>.paragraph{background-color:red;}
    </style>
    </head>
    <body>
        <div>
        <h1 class="title">习近平心中的互联网</h1>
        <p class="paragraph">互联网是20世纪最伟大的发明,它正在将人类“一网打尽”,人们在不知不觉中已经融入了互联网生态,互联网让世界变成了“鸡犬之声相闻”的地球村。</p>
        </div>
    </body>
</html>
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <style type="text/css"> h1,p,.NO1{ color:red; background-color:#88ff66; } </style> </head> <body> <h1>习近平心中的互联网</h1> <p>互联网是20世纪最伟大的发明,它正在将人类“一网打尽”,人们在不知不觉中已经融入了互联网生态,互联网让世界变成了“鸡犬之声相闻”的地球村。</p> <div class="NO1">习近平指出:“互联网已经融入社会生活方方面面,深刻改变了人们的生产和生活方式。”</div> </body> </html>
soumettreRéinitialiser le code
chapitredidacticiel