P粉1037395662023-08-31 10:34:27
Next time please share your code instead of screenshots, anyway, here is a sample code that does not use z-index
HTML
<div class="container"> <div class="your-image"> </div> <div class="your-boxes"> </div> </div>
CSS
.container { display: grid; grid-template-rows: 1 / 1; grid-template-columns: 1 / 1; justify-items: center; align-items: center } .your-image { background-color: red; width: 250px; height: 250px; grid-area: 1 / 1 / 1 / 1; } .your-boxes { background-color: green; width: 150px; height: 150px; grid-area: 1 / 1 / 1 / 1; justify-self: center; }
Basically, you create a 1x1 grid and overlap two divs on the same column and row.
https://codepen.io/ChrisCoder9000/pen/NWMJdBo