Hi,
I’m wanting to do a two column layout that basically stacks two separate divs on the left to create the left sidebar. Then the main div on the right would fill the rest of the space and match the sidebar height and vice versa.
Here’s the kicker though, I need those three divs nested in one wrapping div so I can stack them correctly when the media query kicks in.
I can nest the two sidebar divs in a parent div and accomplish this easy, but I can’t distribute them correctly when the media query kicks in since they are trapped in the parent.
Here’s some pics of what I am trying to accomplish…
Before media query (Desktop)
After media query (Mobiles)
The after image was easily created with this html structure…
I’m not sure what you are requesting, Ray. I copied your “after screen shot” code to my PC and opened it in FF. It seems to demonstrate both the desktop and mobile views as shown. Did you want the side boxes distributed differently? Maybe that’s what I’m missing.
On desktop the sidebar blocks need to stack, as seen in my before (desktop) pic.
That desktop pic was created with different code, but it will not give me the mobile version I’m after.
You will see that I had to nest the sidebar divs in a parent div .left , but that will not get the mobile view I want.
EDIT:
The Gold box “Side Top” is going to be my nav menu for desktops, then it will be a toggle menu for mobiles.
The Pink box “Side Bottom” is going to be <aside> content, but I don’t want to discard it when media queries kick in. I want it to go above the footer.
Here’s the code that gives the desktop view I want…
I’m trying to come up with code that produces the results of the desktop and mobile pics from post#1.
I know it sounds confusing, I had to write two pieces of code to create the desktop/mobile screenshots. The screenshots represent what I am trying to get one code to do.
The problem is it needs to be a flex column to get that stacking. But to make the column wrap so the main starts a new column you need to constrain the parent height which I imagine you will want to avoid.
This may be more a case for grid rather than flex.
I knew this wasn’t as easy as it looks. I see it work with a height like you said, but of course that’s not feasible.
I have no interest in using grid due to browser support at this time.
I can get the desktop view by floating the sidebar blocks, they would have to come first in the html source though. Then I can’t rearrange the order when media queries kick in for mobile.
EDIT:
Here is the code using height and it gives the desktop and mobile views I’m after, but it is useless with height set.
Although I am having trouble keeping the sidebars at a fixed width while main content fills the rest of the space.
It would be if all the browsers supported display:contents which was built for purposes like these.
@media all and (max-width: 600px) {
.left{display:contents}
}
If you view your page in Firefox only then it works as you want.
I would suggest that as its only the mobile view that needs that layout then you use flexbox as you have done for larger screens and then just use grid for the smaller view as support is good in mobile. I haven’t tested if its possible with grid yet with the structure you are using and it may be the same issue as flex. I am not near a computer at the moment but I’ll try and have a go later or tomorrow.
Had a quick look at grid and it seems it suffers from the same problems as flex in that items in the grid can’t be moved out of the current grid parent. I did read there was something called a subgrid which may offer that facility but is not implemented by any browser yet. It may be that I am not just seeing the obvious but I’ve only glanced briefly at grid as it seems overly complex to me and usually the layout can be done more easily with other means.
It’s funny though in that I have a layout from about 15 years ago that can nearly do what you want?
It’s a bit hacky and all smoke and mirrors but I love the way that the old school css could do things. Flex and grid are great but very specific in what they do. I’d rather just be given bricks and let me build the house how I want
I loved Lego as a kid. I used to make anything I could dream of just out of basic bricks. Now I look at Lego, with all these custom components, and it just turns me off.
Was that mobiles could just get display:block and be done. So mobile support for grid is not really the issue. Even though they have better support than desktop.
I think I’ve got something I can work with now. Was able to put together an example using all floats on the three nested divs.
Doing that I was able to keep the html just like I posted it above in #16.
Got real close using inline-table but hit one little snag that caused my lower side bottom div to be out of the flow. The side top div would no longer push it down.
I think this layout using all floats wound up being the most stable code. The linear-gradient backgrounds sure are handy for faux columns. A calc() width helped eliminate the need for an extra wrapping div we used to need also.
I’ll post the code for posterity should my link disappear someday.