I am attempting to create a style that only affects the first grandchild of the main container. The structure is as follows:
.container {
display: flex;
}
.container.main {
border: 1px solid gray;
}
.container.main .item>* {
border-color: red;
}
.item {
width: 30px;
height: 30px;
border: 1px solid blue;
margin: 1px 1px 2px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<div class="container main">
<div class="container">
<div class="item"></div>
<div class="container">
<div class="item">
</div>
<div class="container">
<div class="container">
<div class="container">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="container">
<div class="item"></div>
<div class="item"></div>
</div>
</div>
</div>
<div class="item"></div>
</div>
</div>
</div>
</div>
</body>
</html>
I would like to make the first child yellow and the last child dotted. How can I achieve this? Each child could be nested at different levels in various containers.