CSS Basics - Selector Advanced, Background Related Properties (Color/Image)
Goal: Be able to understand the rules of compound selectors and use compound selectors to select elements in HTML
Learning path: 1. compound selector 2. union selector 3. intersection selector 4. hover pseudo class selector 5. Emmet grammar
What we have learned this time:
1. Advanced selector
1.1 Descendant selector: space
➢ Function: According to the nesting relationship of HTML tags, select elements that meet the conditions in the descendants of the parent element
➢ Selector syntax: selector1 selector 2 { css }
➢ Result:
• Among the descendants (son, grandson, great-grandson...) of the label found by selector 1, find the label that satisfies selector 2 and set the style
➢ Points to note:
\1. Offspring include: son, grandson, great-grandson...
\2. In the descendant selector, the selector is separated from the selector by a space
1.2 Child selector:
➢ Function: According to the nesting relationship of HTML tags, select the element that satisfies the condition in the child of the parent element
➢ Selector syntax: selector1 > selector 2 { css }
➢ Result:
• Among the children (sons) of the label found by selector 1, find the label that satisfies selector 2 and set the style
➢ Points to note:
\1. Children only include: son
\2. In the child selector, the selector is separated from the selector by >
2.1 Union selector:,
➢ Function: Select multiple groups of labels at the same time and set the same style
➢ Selector syntax: selector1, selector 2 { css }
➢ Result:
• Find the label selected by selector 1 and selector 2, and set the style
➢ Points to note:
\1. Each group of selectors in the union selector is separated by ,
\2. Each set of selectors in the union selector can be a basic selector or a compound selector
\3. Each group of selectors in the union selector is usually written one per line to improve the readability of the code
3.1 Intersection selector: right next to
➢ Function: Select tags that satisfy multiple selectors in the page at the same time
➢ Selector syntax: selector 1 selector 2 { css }
➢ Result:
• (both in principle) Find the label that can be selected by both selector 1 and selector 2 in the page, and set the style
➢ Points to note:
\1. The selectors in the intersection selector are next to each other, and there is no separation
\2. If there is a label selector in the intersection selector, the label selector must be written at the top
4.1 hover pseudo class selector
➢ Function: select the state when the mouse is hovering over the element, and set the style
➢ Selector syntax: selector:hover { css }
➢ Points to note:
\1. A certain state of the element selected by the pseudo-class selector
5.1 emmet syntax --- quickly generate code through abbreviated syntax
Quick code generation:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div { /* font-size: ; */ font-size: ; /* Prompt css attribute: the first letter of the word */ /* font-weight: ; */ font-weight: 700; width: ; height: ; /* background-color: ; */ background-color: #fff; /* line-height: ; */ line-height: ; /* The width is 300, the height is 200, and the background color is pink */ /* w300+h200+bgc */ width: 300px; height: 200px; background-color: pink; } </style> </head> <body> <div></div> <h1></h1> <!-- generate div with class name --> <div class="box"></div> <p class="box"></p> <div id="box"></div> <p id="box"></p> <p class="red" id="one"></p> <!-- div at the same level p + --> <div></div> <p></p> <!-- Father and son > --> <div> <p></p> </div> <ul> <li></li> </ul> <!-- ul there are 3 li *Multiplication sign --> <ul> <li></li> <li></li> <li></li> </ul> <!-- ul There are 3 inside li, li It has the text 111 inside {Word} --> <!-- ul>li{111}*3 --> <ul> <li>111</li> <li>111</li> <li>111</li> </ul> <!-- ul there are 3 li, li text 1, 2, 3 --> <!-- ul>li{$}*3 --> <ul> <li>1</li> <li>2</li> <li>3</li> </ul> </body> </html>
2. Context related attributes
Goal: To be able to use background-related properties to decorate the background style of an element
Learning path: 1. background color 2. Background picture 3. background tiling 4. background position 5. Linking of background related attributes
1.1 Background color
test:
summary
➢ What is the property name of the background color property? • background-color ➢ What is the default attribute value of the background color attribute? • transparent: rgba(0,0,0,0),transparent
2.1 Background image
test:
3.1 Background tiling
test
summary:
4.1 Background position