
Style whole sections with one smart rule
Let’s continue with the CSS Basics. If you haven’t read the previous article, make sure to read it first.
Nested Styling
CSS allows for nested HTML element styling. In the example below, we have two paragraph tags. Each paragraph has a link and a button.
<p id="first-p">
<a href="#">Link 1</a>
<button>Click Me</button>
</p>
<p id="second-p">
<a href="#">Link 2</a>
<button>No, Click Me</button>
</p>
Since neither the link, nor the button, has neither an id nor a class attribute, we must specify their styles through nesting. To select the link contained inside the first paragraph, we would write the following CSS code:
#first-p a { font-weight: bold; }
<a> tag inside the #first-p paragraph. To add a style to both buttons inside the paragraph tags only and exclude the buttons outside of the paragraph tags, the following CSS code can be written:p button { background-color: coral; }
The styles were applied, and the results below were produced.

Styling can be applied to child elements, but not to descendants by using the greater than symbol >. In this example, we’ll have a <section> parent, one <button> child, one <p> child, and one <button> descendant.
<section>
<button>Child Button</button>
<p>
<button>Descendant Button</button>
</p>
</section>
/* CSS */
section > button { background-color: skyblue; }

Styling Multiple Elements
CSS has a lot of flexibility on how you specify the selectors and apply the styles to them. To add a style to multiple HTML elements, we’ll separate each element with a comma. For example, if we wanted to change the color of the <h1>, <h2>, and <h3> tags, we could write the following code:
h1, h2, h3 {
color: royalblue;
}
<section>
<button class="first-button">Child Button 1</button>
<button id="second-button">Child Button 2</button>
<a href="#">Child Link</a>
<p>
<button>Descendant Button</button>
</p>
<div>
<a href="#">Descendant Link</a>
</div>
</section>
/* CSS */
p, div, section > a { padding: 10px; }
.first-button, #second-button, div > a {
background-color: skyblue;
padding: 5px;
}
The first style adds a 10px padding to any paragraph element, any div element, and any child link of the section element. The second style adds a sky blue background color and a 5px padding to the first-button class, the second-button id, and any child link of the div tag. The third style adds a 10px top margin to any child button of the paragraph tag and any child link of the section tag.

CSS Series
Continue your Laravel Learning.
Style whole sections with one smart rule
Part two of our CSS fundamentals series dives into basic styling skills. Define colors, fonts, borders, and simple layout tweaks while learning selector specificity and inheritance—everything you need to transform raw HTML into visually engaging content.
Style whole sections with one smart rule
CSS — P3: Nested Styling and Styling Multiple Elements
Part three of our CSS fundamentals series introduces nested selectors and group styling. Learn descendant, child, and pseudo-class nesting, comma-separated selectors, and BEM-friendly patterns that let you style multiple elements with clean, maintainable rules.
Fine-tune styles with smart selectors
CSS — P4: Pseudo-Class Selectors & Selector Precedence
Part four of our CSS fundamentals series demystifies pseudo-class selectors—from :hover and :nth-child() to :not()—and shows how specificity and source order decide who wins when styles collide. Build predictable, accessible interactions with confidence.

