Grouping Selectors in CSS
The CSS grouping selector is used to select multiple elements and style them together. This reduces the code and extra effort to declare common styles for each element. To group selectors, each selector is separated by a space.
Mục Lục
Syntax
The syntax for CSS grouping selector is as follows −
element, element { /*declarations*/ }
The following examples illustrate CSS grouping selector −
Example
Live Demo
<!DOCTYPE html> <html> <head> <style> article, p, img { display: block; margin: auto; text-align: center; border-bottom: double orange; } </style> </head> <body> <article>Demo Text</article> <p>This is demo text.</p> <br/> <img src="https://www.tutorialspoint.com/swing/images/swing.jpg"> </body> </html>
Output
This gives the following output −
Example
Live Demo
<!DOCTYPE html> <html> <head> <style> div::after,p::after{ content: "Demo text"; margin: 4px; box-shadow: inset 0 0 4px darkorange; } </style> </head> <body> <div></div> <p>This is example text.</p> </body> </html>
Output
This gives the following output −