Two Column Layout, but the other one goes to edge.
Hi everyone, may I ask the best way to make a layout like this responsively?
The red square will be an image.
The red line indicates the container of the site. But the image should go way to the edge of the view port.
Thank you for the response.
9 Replies
TLDR; The content should be inside the container but the image should span to the right edge
Use relative positioning + negative margin on the image container.
Example:
With the tools available nowadays like grid this solution is kind of hack imo
But also depends on the project size and use case
Setting up a grid system like this could do it but if it’s a small project , I may instead use a pseudo element for the image
Kevin Powell
YouTube
A new approach to container and wrapper classes
The wrapper or container is probably the most common design pattern around, but after coming across an article by Stephanie Eckles looking at how we can use a grid to emulate a container, and have simple breakouts — https://smolcss.dev/#smol-breakout-grid — I had an idea of how we could do this to completely drop the idea of containers, and then...
Oh, neat! That is indeed a much more elegant solution. Updating my previous answer:
If you want to stick to the naming concept of grid-lines, you could create another grid-line-name of [center-line] min(100% - (var(--padding-inline) * 2), 100% / 2; that way you could over-engingeer this correctly and change .image-section { grid-column: center-line / full-width-end
Hi everyone, I'm sorry for the late response. But here is my attempt to replicate the situation, The image should still respect the container but should stretch until the edge of the screen on the other side.
Is there a way to make it responsive so that it fits naturally and do not overlap the screen? Like do I need calc for that?
https://codepen.io/Jeremy-Mapalad-the-encoder/pen/JoPPLRj
Thanks for the response! But what if my columns are not equal, for example left section is col-4 and the right section which has an image is col-8?
I would avoid using
vw
as a hard unit. It will not account for scrollbars. %
or grids fr
is a better option. Ultimately I would use grid and probably something like what missfox linked (its teh way).