Overlapping css grid problem

Helllo, I try to make 3 div's overlapping each other. So far I have this : https://codepen.io/RoelofWobben/pen/JojOzqz Can anyone help me figure out how on the top left in the image div a little div can be added so it overlaps the overlay div ?
11 Replies
clevermissfox
clevermissfox2w ago
Maybe someone else will grasp your description but I would need a sketch or figma wireframe or some kind of example of what you're going for of how small and where the overlap is and what does the others side of the new small div overlap onto
roelof
roelofOP2w ago
The overlay is the red area @clevermissfox I hope this picture is then more clear this is what I try to achieve
roelof
roelofOP2w ago
No description
clevermissfox
clevermissfox2w ago
I see the red box is the overlay I just didn’t know what you wanted to add. You can use named grid lines for overlapping content.
Css
grid-template-columns: [new-start overlay-start] 2rem [new-end] 1fr [overlay-end header-start content-start] 2fr [header-end content-end]
Css
grid-template-columns: [new-start overlay-start] 2rem [new-end] 1fr [overlay-end header-start content-start] 2fr [header-end content-end]
Here’s an example of how you can use it on cols , give it a try and of course adjust the column sizes to the values you want . Then give it a try to set up the grid-template-rows using name grid lines. And don’t forget to see the grid area name on the new element ( I called it “new” on this example but give it a more appropriate name )
roelof
roelofOP2w ago
I tried that on the pen but now the overlay2 is just as big as the overlay
clevermissfox
clevermissfox2w ago
Like I said you will need to adjust the values and also make sure to set the grid rows up And make sure to comment out your grid-template-areas as it’s not ideal for keeping overlapping content simple
roelof
roelofOP2w ago
o, I thought this example was easy and simple enough to adapt : https://gridbyexample.com/examples/example22/
Chris Bolson
Chris Bolson2w ago
What size do you want it be?
clevermissfox
clevermissfox2w ago
My perspective is that it’s simple to adapt - you just need to make some adjustments on how you declare the grid template . I find the grid areas overlap hack to be a little more confusing so didn’t want to bring it up but maybe you’ll find it easier to work with than named grid lines 1. change two lines of css on the grid template columns and grid template rows 2. comment out the grid template areas for now 3. then make sure you assign “overlay2” grid area name to the new element
Rägnar O'ock
Rägnar O'ock2w ago
When trying to overlap stuff in a grid it's important to remember that when you define a set of rows and columns named <area>-start and <area>-end they will define a virtual area that you can use with grid: area just like any other. With that in mind you also have to remember that you can define both areas and track names with the grid-template or grid shorthands. So you can do something like this :
grid:
[green-start] '[green-start] red [green-ene] red . ' 50px
[green-end] 'red red .' 20px
'red red content' 1fr
/ 50px 100px 1fr
grid:
[green-start] '[green-start] red [green-ene] red . ' 50px
[green-end] 'red red .' 20px
'red red content' 1fr
/ 50px 100px 1fr
(that only does the red, green and content areas, the light grey one is left as an exercise to the reader)
roelof
roelofOP2w ago
Thanks both

Did you find this page helpful?