Book Top Rank with Contact Details visibility for your Business, Profession, Products or Services

How do you group selector in CSS

Question by Saravana s On 03 August 2022, 16:26:57

(Page Views: 183)

Answer by Saravana s On 03 August 2022, 16:28:16

What is Group Selector in CSS

selector1, selector2,..
  Declaration list;

A group selector is a way to select multiple HTML elements in CSS and give the same style to everything. To implement a group selector, we write a comma-separated list of selectors. Create a group selector to reduce code redundancy when different tags have similar styles. If you don't put a comma in the group selector, then the inside element will be selected instead of other elements. For example, if you put a p tag inside a Div element, then only that p tag will be selected. There are three types of group selectors:

  1. Element group selector
  2. Class group selector
  3. ID group selector

Element group selector

p, h3{
background-color: grey;
color: black;

Class group selector

.p1, .head1{
  text-decoration: underline;
  color: darkblue;

ID group selector

#p1, #head1{ 
 font-family: sans-serif; 
 color: darkviolet; 

Read more about group selector