CSS Basics Tutorial Combination Selector
Multiple element selector
## Description: Add the same style to multiple elements, multiple Selectors are separated by commas ",".
Example: 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>習(xí)近平心中的互聯(lián)網(wǎng)</h1> <p>互聯(lián)網(wǎng)是20世紀(jì)最偉大的發(fā)明,它正在將人類“一網(wǎng)打盡”,人們?cè)诓恢挥X(jué)中已經(jīng)融入了互聯(lián)網(wǎng)生態(tài),互聯(lián)網(wǎng)讓世界變成了“雞犬之聲相聞”的地球村。</p> <div class="NO1">習(xí)近平指出:“互聯(lián)網(wǎng)已經(jīng)融入社會(huì)生活方方面面,深刻改變了人們的生產(chǎn)和生活方式?!?lt;/div> </body> </html>
Descendant element selector (most commonly used)
Description : Add styles to a descendant element of a tag. Selectors are separated by "spaces".
Example: 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">習(xí)近平心中的互聯(lián)網(wǎng)</h1> <p class="paragraph">互聯(lián)網(wǎng)是20世紀(jì)最偉大的發(fā)明,它正在將人類“一網(wǎng)打盡”,人們?cè)诓恢挥X(jué)中已經(jīng)融入了互聯(lián)網(wǎng)生態(tài),互聯(lián)網(wǎng)讓世界變成了“雞犬之聲相聞”的地球村。</p> </div> </body> </html>
Child element selector
Description: Add styles to the child elements of an element.
- ##Example
: 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">習(xí)近平心中的互聯(lián)網(wǎng)</h1> <p class="paragraph">互聯(lián)網(wǎng)是20世紀(jì)最偉大的發(fā)明,它正在將人類“一網(wǎng)打盡”,人們?cè)诓恢挥X(jué)中已經(jīng)融入了互聯(lián)網(wǎng)生態(tài),互聯(lián)網(wǎng)讓世界變成了“雞犬之聲相聞”的地球村。</p> </div> </body> </html>