DEV Community

Abhii
Abhii

Posted on

1 2

.parent .child vs .parent > .child css selector

Introduction

The .parent .child selector

The .parent > .child selector

After words

styles.css

body {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-size: 1.5rem;
    color: #fff;
}
.parent .child {
    background: darkblue;
    margin: 1rem;
}
.parent>.child {
    background: brown;
}
Enter fullscreen mode Exit fullscreen mode

index.html

<div class="parent">
    <div class="child">This is brown</div>
    <div class="one">
        <div class="child">This is yellow</div>
    </div>
</div>

<div class="parent">
    <div class="one">
        <div class="child">Why is thid yellow?</div>
    </div>
</div>
Enter fullscreen mode Exit fullscreen mode

Inspiration

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay