In the realm of CSS, selectors are the backbone of styling web content. They allow us to target specific HTML elements and apply styles to them. However, when it comes to selecting multiple elements, things can get a bit tricky. This article aims to demystify the 'CSS not selector multiple' conundrum and provide a comprehensive guide on how to select and style multiple elements effectively.
Understanding CSS Selectors
Before delving into selecting multiple elements, it's crucial to have a solid understanding of CSS selectors. Selectors are patterns used to match HTML elements in a document. They can be simple, like an element name (e.g., `p` for paragraph), or complex, combining multiple selectors.
Selecting Multiple Elements: The Basics
CSS provides several ways to select multiple elements. The most common methods are using commas, descendant selectors, and child selectors. Let's explore each of these.

Using Commas (,)
You can select multiple elements by separating them with commas. This tells the browser to apply the specified styles to all the listed elements. For example, the following CSS will select all `p`, `h1`, and `h2` elements and make their text color red:
```css p, h1, h2 { color: red; } ```
Descendant Selectors (space)
Descendant selectors match elements based on their relationship in the document tree. Using a space between selectors matches any descendant of the first selector that is also a match for the second selector. For instance, the following CSS will select all `p` elements inside any `div`:
```css div p { font-style: italic; } ```
Child Selectors (>)
Child selectors match only the direct children of the specified parent. Using the `>` symbol between selectors matches any element that is a direct child of the first selector. For example, the following CSS will select only the first-level `p` elements inside any `div`:

```css div > p { font-weight: bold; } ```
Selecting Multiple Classes and IDs
You can also select multiple classes and IDs using the `.` and `#` symbols respectively. However, unlike element selectors, you cannot separate classes and IDs with commas. Instead, you can use the `:not()` pseudo-class to select elements that do not match a certain class or ID.
Using :not()
The `:not()` pseudo-class matches elements that do not match a list of selectors. For instance, the following CSS will select all `p` elements that do not have the class `important`:
```css p:not(.important) { color: gray; } ```
Selecting Multiple Elements with Attribute Selectors
Attribute selectors allow you to select elements based on their attributes. You can use them to select multiple elements with the same attribute value. For example, the following CSS will select all `a` elements with the `href` attribute containing the value `example.com`:

```css a[href*="example.com"] { text-decoration: underline; } ```
Selecting Multiple Elements with Pseudo-Classes
Pseudo-classes allow you to select elements based on their state or position. You can use them to select multiple elements that share the same state. For instance, the following CSS will select all the first `p` elements in each `div`:
```css div p:first-child { font-style: italic; } ```
Selecting Multiple Elements with Grouping
You can group selectors using commas to apply different styles to the same elements. This is useful when you want to apply different styles to the same elements based on their state or position. For example, the following CSS will select all `a` elements and apply different styles based on their state:
```css a { color: blue; text-decoration: none; } a:hover { text-decoration: underline; } a:active { color: red; } ```
Conclusion
Selecting multiple elements in CSS is a powerful way to apply styles efficiently and effectively. Whether you're using commas, descendant selectors, child selectors, attribute selectors, or pseudo-classes, understanding how to select multiple elements is a crucial skill for any web developer. By mastering these techniques, you'll be well on your way to creating responsive and stylish web pages.





















