0% completed
Grouping and combining selectors let you apply the same style to different elements. This method makes your CSS shorter and easier to maintain. You can group selectors to share common properties or combine them to target elements based on multiple conditions.
Using grouping means you can write one rule for many selectors. Combining simple selectors means you can target elements that meet several criteria at the same time.
Follow below syntax to group and combine simple selectors in CSS code.
selector1, selector2, selector3 { property: value; }
Explanation:
When combining selectors without commas, you target elements that meet all criteria. For example:
element.class { property: value; }
Explanation:
In this example, we will group multiple element selectors to apply the same style to them. The example applies a shared color and font family to headers and paragraphs.
Explanation:
<h1>
and <p>
are styled identically as defined.In this example, we will combine an element selector with a class selector. The example targets only list items within a list that have a specific class.
Explanation:
<li>
elements that include the class "active".This lesson demonstrates how to group selectors to apply the same style to different elements and combine selectors to target specific elements that meet multiple conditions. These techniques simplify your CSS and help you create a more organized and efficient style sheet.
.....
.....
.....