It seems that you want to group the divs by 2. It is not possible to do it with pure CSS. You can write this:
.item {
width: 20px;
height: 20px;
border: solid;
}
.item:nth-child(odd):hover, .item:nth-child(odd):hover + div {
background-color: blue;
}
<div>
<div class="item div1"></div>
<div class="item div2"></div>
<div class="item div3"></div>
<div class="item div4"></div>
<div class="item div5"></div>
<div class="item div6"></div>
</div>
Here, every odd div changes its own color and the color of the div right after that, using "+" which is the "Adjacent sibling selector". Unfortunately, this operator only selects the next sibling and CSS has no solution for selecting the previous sibling.
If you insist on grouping them by two, you can either use Javascript:
const items = document.querySelectorAll('.item');
items.forEach((item, i) => {
item.addEventListener('mouseover', function() {
const siblingPosition = i % 2 === 0 ? 'nextElementSibling' : 'previousElementSibling';
item.classList.add('active');
item[siblingPosition].classList?.add('active');
})
item.addEventListener('mouseout', function() {
items.forEach(it => it.classList.remove('active'))
});
});
.item {
width: 40px;
height: 40px;
border: solid;
}
.active {
background-color: blue;
}
<div>
<div class="item div1"></div>
<div class="item div2"></div>
<div class="item div3"></div>
<div class="item div4"></div>
<div class="item div5"></div>
<div class="item div6"></div>
</div>
Or actually, group them in HTML level which in my opinion is a better solution.