I created several child elements with different classes and I need to select first child element with specific classname which is sibling of another child element with different calssname. How to select all first and last children after some specific sibling?
I tried to select last-child and first-child, but worked only last child, first child is not selected
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<h1>hello</h1>
<div class="parrent">
<div class="child2">child2</div>
<div class="child1">child1</div>
<div class="child2">child2</div>
<div class="child2">child2</div>
<div class="child2">child2</div>
<div class="child1">child1</div>
<div class="child1">child1</div>
<div class="child2">child2</div>
<div class="child2">child2</div>
</div>
</body>
</html>
CSS
.parrent>div {
color: green;
}
.child1 ~ .child2:first-child {
color: red;
}
.child1 ~ .child2:last-child {
color: red;
}
I expected to select all first and last children of .child2
which are sibling to (which are stay after) .child1
But I got: