JSFiddle - React, Tailwind, and code Playground
HTML
<div class="container">
<div class="box">Box 1</div>
<div class="box">Box 2</div>
<div class="box">Box 3</div>
<div class="box">Box 4</div>
</div>
CSS
.container {
display: flex;
gap: 20px;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
}
.box {
width: 100px;
height: 100px;
background-color: #3498db;
transition: opacity 0.3s ease;
display: flex;
justify-content: center;
align-items: center;
color: white;
font-family: Arial, sans-serif;
border-radius: 8px;
}
/* When container has a hovered element, reduce opacity of non-hovered boxes */
.container:has(.box:hover) .box:not(:hover) {
opacity: 0.5;
}