Forum Moderators: not2easy

Message Too Old, No Replies

Trying to make a 2-column layout where one column can slide away

         

l008comm

9:25 am on Dec 28, 2023 (gmt 0)

10+ Year Member Top Contributors Of The Month



I'm working on a web page that is specifically intended to be used on tablets. The layout is that by default, there is a navigation column on the left, and the main content on the right. The nav does not render on TOP of the content, but next to it. And I want the user to be able to click a button to make the navigation column slide away into nothingness allowing the main content to fill the whole screen.

My first thought was to simply have a parent with display: flex; and then the menu column child have flex: 25%;. Then with a css transition, use JS to swap classes to that column is flex: 0%;

That failed for not one but TWO reasons!
First, the min "flex" size is limited by the longest word in the column. It can't get any smaller than that, the text keeps the column "propped open" essentially.
Second, even if it did work, it is "squeezing" the content out of existing in a very unpleasing way. Thats not actually what I want, I want the whole column to just slide off the page to the left without changing its width, so without changing the text flow at all. And then just let the remaining column fill up the whole space.

Any thoughts on how best to accomplish this? I tried using width instead of flex but that still doesn't work the way I'd like at all.

I have a mockup you can view and play with. it's kind of 'large format' for use in a jsfiddle but its the best I can do:

[jsfiddle.net...]

Note: Click on the plain text "Toggle Nav Menu" at the top to attempt to hide and show the nav column.

l008comm

9:40 am on Dec 28, 2023 (gmt 0)

10+ Year Member Top Contributors Of The Month



I was able to get much closer to the desired affect by using margin-left to slide the navigation column off the left edge of the page. It has some weird spacing issues with the borders but I can probably clean those up once I apply the real styling of the site:

[jsfiddle.net...]

So I guess now the question is, is that method as good as it gets, or is there a way to even improve upon that?

lucy24

4:46 pm on Dec 28, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



limited by the longest word in the column
If it's just the occasional sesquipedalian word messing everything up, ­ is your friend.

londrum

6:12 pm on Dec 28, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



it works well, but it's possible to do it just with CSS, which will get rid of all that javascript code
if you search for "CSS collapsable div using input and labels"

l008comm

12:55 am on Dec 29, 2023 (gmt 0)

10+ Year Member Top Contributors Of The Month



I want to use javascript because there are some other things that are going to happen at the same time. Only the mockup is set up super simply with just one thing happening.