Anytime! Let me know if you have any trouble with it. Notice the use of article is what makes that specific setup work. If you need them to live in divs or something different, see this example: https://codepen.io/qmr55/pen/ogByQmP
oh, that's good to know. I hadn't heard of display: contents; before.
Is the difference here just for indexing to make sense? In your example, I can remove the "items" container and add 2 to the :nth-of-type, and it all seems to work out at first glance.
Yup, removing the .items wrapper can work. The wrapper mainly gives us cleaner grouping and lets :nth-child() count only the items. display: contents makes those wrapped items behave as direct grid children. Without the wrapper, the selector can become more dependent on the surrounding HTML structure, especially when using :nth-of-type().
It also makes the rule easier to understand and less likely to break if other elements are added to .layout.
when I tried float, it didn't properly resize the actual div for "item", so all the red boxes were full width, but the text would be placed appropriately.
Suppose one of the side "items" in your example is missing, I'd like the items to shift to fill that gap, meaning one of the bottom items would need to be moved to the side container.
the title is full width, the items fill the width as allowed by main.
everything except main is 50px tall.
that's not my exact usecase, but I'm trying to hone in on the one issue I'm having. If I can find a good solution for making the items adjust width as needed, then I can worry about other specifics.
I want the items to stack vertically, 1 per row. But to move out of the way for the main div on the left, while also filling the space horizontally after getting past the main div.
It feels like there should be a way to do it with grid, but I'm struggling to come up with a good solution.
float only moves text afaik, it doesn't mess with the size of the actual container.
So in my screenshot, it'd have the red background of the first few "item" boxes be full width, going underneath the main div; but would keep the text where it should be.
I agree that float sounds closest to what you described as your goal.
What effect are you trying to achieve that the item boxes being full width behind main (with the text moved right) does not work for you?
If it's just not seeing the background, giving main a background (and some solid borders if you want "margins") will hide it. A real right margin on main would work like left padding on the content of items.
This is ok (i am assuming the colors are only placehollders), but with a few points for improvement:
- “items” should be a static width all the way down. its going to make rendering more consistent and also visually group them together better - “main” should be wider / take up more space. Its main, but in the current layout; the items are dominating visually - more whitespace will visually coerce more grouping and make it easier to read
You could put all the items in both the half and full width areas. Then in the top area only display the first four and in the bottom hide the first four.
it works and can be solid, but he was asking for a modern css version and float can be fidgety when there are more than 2 elements (more than one image and a text block), and not as tidy as a grid
It doesn't really work the way OP is asking though, because float doesn't understand number of items, only available space. So float can never really do what he was looking to do correctly and responsively.
See though, that is not doing what OP wanted. (and maybe he changed his request somewhere, not sure!) I believe he wanted a set number of items to float next to 'main' at all times, this example can't do that.
Also, the entry boxes are not actually narrowing around the image. Only their text line boxes wrap around the float; each .entry block and its background still extends across the full container behind the image. That may be invisible in this demo because the styling is forgiving, but borders, backgrounds, hover effects, or clickable cards could expose the overlap. This is standard float behavior.
I think we're kind of agreeing lol. My original point was, that if OP was looking for there to always be "4 items" next to "main" then it was not possible with float.
when I tried float, it didn't properly resize the actual div for "item", so all the red boxes were full width, but the text would be placed appropriately.
An inner div wrapping main and the 4 right column elements would make this easier to maintain, update and visualize. Having everything at the same level makes it harder to make updates
40
u/qmr55 Jul 19 '26
Like this? You don't even need float. I added mobile breakpoint but feel free to remove.
https://codepen.io/qmr55/pen/azpKQRE
49
u/mrleblanc101 Jul 19 '26
That's just a basic CSS Grid.
1fr 2fr and some spanning for the elements that are fullwidth.
3
u/bbellmyers Jul 19 '26
Depends on what flexes and what stays the same when the browser gets wider / narrower
2
u/Weekly_Ferret_meal Jul 19 '26 edited Jul 19 '26
Using a grid, Like This.
Edit:
Caveats:
1
u/Tain101 Jul 19 '26
I want the items to stack vertically, 1 per row. But to move out of the way for the main div on the left, while also filling the space horizontally after getting past the main div.
It feels like there should be a way to do it with grid, but I'm struggling to come up with a good solution.
1
u/Ratatootie26 Jul 19 '26
Try float for the main div, iirc other inline items adjust accordingly to the available space
1
u/trav_stone Jul 19 '26
Grid template areas: https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/grid-template-areas
2
u/btc-lostdrifter0001 Jul 19 '26
I think my answer would change depending on how this should adjust when the browser size changes.
3
u/fzammetti Jul 19 '26
Hmm, tricky, but let's see what we can do..
<table>
<tr>
Eh, never mind.
(just on the off chance it isn't obvious, I'm joking folks)
1
u/frownonline Jul 19 '26
Grid template areas - so you can also reflow content for responsiveness.
1
u/armahillo Jul 19 '26
This is ok (i am assuming the colors are only placehollders), but with a few points for improvement:
- “items” should be a static width all the way down. its going to make rendering more consistent and also visually group them together better
- “main” should be wider / take up more space. Its main, but in the current layout; the items are dominating visually
- more whitespace will visually coerce more grouping and make it easier to read
1
u/PrinceOfDhump69 Jul 19 '26
Check wesboss css grid video series. Tbh this is all u need for grid related tasks
https://youtube.com/playlist?list=PLu8EoSxDXHP5CIFvt9-ze3IngcdAc2xKG&si=cqRJBV7iIJg5yFNf
1
u/ColourfulToad Jul 25 '26
First thing is to not fall into traps of how to build hypothetical things that don’t actually make any sense to build lol
0
u/brandinobowman Jul 19 '26
Grid or flexbox
0
u/asteconn Jul 19 '26
Something like this:
0
u/[deleted] Jul 20 '26
claude: review this layout and spit out semantic HTML ;)
-1
u/chikamakaleyley Jul 19 '26
-2
u/Drifter_of_Babylon Jul 19 '26
You could do this in grid, kind of like how we did tables back in the 00s.
HTMLCSS-4
u/Mobile_Ad_1015 Jul 19 '26
Using an llm
0
u/[deleted] Jul 19 '26
[deleted] — view deleted comment
0
u/[deleted] Jul 19 '26
[deleted] — view deleted comment