This page shows different complex selector combinations in action. Buttons inside nav have a blue background. Only direct li children of ul have square bullets. Paragraph immediately after h2 is bold and red. Cards after the first card have gray borders.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Complex Selector Demo</title>
<style>
nav button {
background-color: lightblue;
border: none;
padding: 0.5rem 1rem;
margin: 0.25rem;
cursor: pointer;
}
ul > li {
list-style-type: square;
color: darkgreen;
}
h2 + p {
font-weight: bold;
color: darkred;
}
.card ~ .card {
border: 2px solid gray;
padding: 1rem;
margin-top: 0.5rem;
}
</style>
</head>
<body>
<nav>
<button>Home</button>
<button>About</button>
</nav>
<section>
<h2>Title</h2>
<p>This paragraph is right after the title and is bold red.</p>
<p>This paragraph is normal.</p>
</section>
<ul>
<li>First item</li>
<li>Second item</li>
<div>
<li>Not direct child, no square bullet</li>
</div>
</ul>
<div class="card">Card 1</div>
<div class="card">Card 2 with gray border</div>
<div class="card">Card 3 with gray border</div>
</body>
</html>