Responsive 2 column layout with header and footer

It should be simple, but I'm still so new to CSS. I'm using 11ty to generate static HTML. I have a CSS file along with it. I'm trying to make a 2-column layout, with header and footer, that looks fine on desktop and mobile. I accept that mobile probably looks different, but I haven't even got the desktop looking right yet. I've got a codepen here: https://codepen.io/rikrose/pen/yLWJZov It appears that my table-of-contents section is too narrow, but I have no idea what's controlling that width. In fact, looking at another page, it appears that the width is uncontrolled, and so varies from page to page. I'm fairly sure I need shorter titles on the sections, but I also need a fixed width, at least on desktop. What have I cross-threaded, and what do I need to go read to learn how to do it correctly?
76 Replies
b1mind
b1mind•8mo ago
First problem I see is you are setting width: 90%; on your body I would avoid using body as any type of wrapper with layout styles in general. But def would not limit its width. Flex will also make its children dense since you are not setting the size its probly shifting based on its siblings content Personally I'd use grid for this 😉
rik
rikOP•8mo ago
Oh. Oops. That 90% was a hangover from one of the guides I was following. Okay. Let's see what I can find here.
b1mind
b1mind•8mo ago
Also I would not use id="" for styles but class=""
rik
rikOP•8mo ago
why is that?
b1mind
b1mind•8mo ago
Kevin Powell
YouTube
Avoid these 5 beginner CSS mistakes
Check out CSS Demystified 👉 https://cssdemystified.com/?utm_campaign=general&utm_source=youtube&utm_medium=beginnermistakestoavoid Here are some common mistakes I see beginners make in their CSS, and a big thank you to Geoff Graham with helping me make this list! My video on the dumb mistakes I keep making: https://youtu.be/GWkMYvoCXyQ ⌚ Time...
b1mind
b1mind•8mo ago
Specificity for one but I tend to look at it more semantically too. id="" has specific use cases for function/labeling. I only use it for that logic not styling logic JS will also make objects for id's so I assume it can have some perf reasons too
rik
rikOP•8mo ago
hm. I was using it because I felt like it was a singleton on the page.
b1mind
b1mind•8mo ago
also don't use tabindex unless you know what you are doiung
b1mind
b1mind•8mo ago
How-to: Use the tabindex attribute - The A11Y Project
tabindex is a global attribute that allows an HTML element to receive focus. It needs a value of zero or a negative number in order to work in an accessible way.
rik
rikOP•8mo ago
thank you. Grid with template columns of 1fr 3fr seems to make things better.
b1mind
b1mind•8mo ago
don't forget you can also use 0.25fr 1fr or what not just find its good to remind people you can use 0.00fr values 🤘 I would note that not setting a width still might shift your nav I would set it maybe with a minmax(20ch, 1fr) or something
rik
rikOP•8mo ago
Interesting. Why would I use a fractional smallest column, rather than scale everything else from it?
b1mind
b1mind•8mo ago
In this case it wouldn't matter don't live in absolutes, I do what works for when I need it.
rik
rikOP•8mo ago
hmmm.
b1mind
b1mind•8mo ago
for my mind its easer to reason with most the times though
rik
rikOP•8mo ago
Hmm. I'll bear that in mind.
clevermissfox
clevermissfox•8mo ago
I agree you should definitely use classes but if for some reason you're not able to add a class and need to target an element with an id, use the attribute selector instead of the high specificity #myContainer. For instance [id=myContainer]{...}. Attribute selectors count as the same specificity level as classes. Some people suggest using the :where () selector with #myContainer as :where() has zero specificity but then you may not be able to override the element selector or defaults. I prefer to keep everything at the same level so using classes or attribute selectors instead of id selectors #myContainer {...} or :where(#myContainer){...}. Just keep it all at the same level. Use classes/attributes for everything above an element sel or use :where() for everything. Even playing field.
b1mind
b1mind•8mo ago
I like that I still tend to never style with id's 😂
rik
rikOP•8mo ago
Thank you.
b1mind
b1mind•8mo ago
def attribute selectors though 🔥
rik
rikOP•8mo ago
I didn't know about ids being overly specific.
b1mind
b1mind•8mo ago
Specificity/Hierarchy(cascade) is a must to learn with CSS
rik
rikOP•8mo ago
I've got a change going in now to switch over to classes. Yep. Live site working nicely now.
clevermissfox
clevermissfox•8mo ago
Me neither but in specific situations I'll select by its ID attr if I'm not able to throw a class on it or it would be complicated to use a descendant selector. But point is OP , don't use ids in your stylesheet eg #myContainer. There are very few hard and fast rules in css but for me personally avoiding id selectors is one hard and fast rule I abide by. The second is avoiding fixed heights 🤣
rik
rikOP•8mo ago
done, on all accounts. And now I have had someone else look, I have a new problem with this layout. It needs to be reactive, and it needs to not be a bad experience on mobile. I did an embedded svg, which seems.to cause calculation and re rendering when you scroll far enough to get to a not-previously-rendered section on a phone, and the TOC definitely overlaps with the text. I think I want the TOC to either snap to the top, or to be in a slide-away drawer. One of these options seems to be much, much more achievable to me than the other. Should I start a new thread for "I want to make this reactive", and one for "I want to improve the experience on mobile"?
rik
rikOP•8mo ago
I thought I had solved the reactive part, but it doesn't appear to work on my phone, and I'm not sure why - the responsive part isn't working. I am trying to use: https://matthewjamestaylor.com/2-column-layouts#responsive-2-column-grid but when using it on https://night-vision-discord.github.io/website/starting-editing/ I'm just getting an overlap and no responsiveness.
Matthew James Taylor
2 Column Layouts (Responsive, Flexbox & CSS Grid)
2 column website layouts in Flexbox, CSS Grid, and Responsive Columns, along with live demos, the HTML, and CSS to make them work.
rik
rikOP•8mo ago
(i'm sticking with grid, as advised yesterday, but I'm onpen to further advice)
clevermissfox
clevermissfox•8mo ago
What does reactive mean if not responsive
rik
rikOP•8mo ago
D'oh. I'm just getting new terms confused. On my desktop, if I shrink the window, eventually the TOC jumps up to the top as a way to skip to the section that you want.
rik
rikOP•8mo ago
On my phone, though...
No description
rik
rikOP•8mo ago
Kevin Powell
YouTube
Useful & Responsive Layouts, no Media Queries required
Conquering responsive layouts: https://courses.kevinpowell.co/conquering-responsive-layouts Here’s 5 quick responsive layouts that you can use, without any media queries! There’s nothing wrong with media queries, and we still need them sometimes, but these can be really handy in the right situation! 🔗 Links ✅ Netflix scroller: https://youtu....
rik
rikOP•8mo ago
Hm. That's a switch to flexbox, which .. while it feels like a good idea, I'm not sure about.
clevermissfox
clevermissfox•8mo ago
Since the table of contents is so long I personally would put it off screen to have it slide in and out . As Kpow always says though, you'll want to progressively enhance so that if the javascript fails users can still interact with the site. What's your hesitation with using flexbox? And is your codepen updated with the latest code that is resulting in your squished phone view?
rik
rikOP•8mo ago
I have updated the pen. What I'm seeing on the phoen doesn't happen on the desktop browser, even with a narrow window - it seems to snap correctly. Having it in a slide-out seems nicer ... but I'm still new enough to CSS that it's not what I believe I want. The second thing is that the background does not work well with a phone. It looks right, but the tiling is painful when scrolling down. My hesitation is mostly because yesterday I was advised to use grid 🙂
clevermissfox
clevermissfox•8mo ago
I'm not seeing any kind of grid setup or media query that would cause the grid to wrap. Are you sure it's the same code ? What I see on the codepen vs what I see on https://night-vision-discord.github.io/website/starting-editing/ is different.
rik
rikOP•8mo ago
Oh shoot. I'm in my kitchen waiting on lunch to cook. I can fix that in a couple of minutes.
clevermissfox
clevermissfox•8mo ago
You can make the background attachment fixed so it doesn't repeat and just covers the whole viewport where the content scrolls over top of it No rush at all
rik
rikOP•8mo ago
It... is there. THere's a rule for @media screen and (mind-width: 768px) near the end Are we suffering because the CSS is processed by SCSS into a single line?
clevermissfox
clevermissfox•8mo ago
this codepen you linked in your post has no @media https://codepen.io/rikrose/pen/yLWJZov?editors=1100
Rik
CodePen
yLWJZov
...
rik
rikOP•8mo ago
uh.. try refreshing? i may have failed to hit save.
clevermissfox
clevermissfox•8mo ago
aha yup there it is Are you sure you saved your code correctly on your github repo? The default style for small screens has no grid so therea no reason the table of contents should be in its own column until the screen hits 768px Bit the styles you had before you saved on codepen where it's default a grid with two columns would explain it. So just double check all your code had been updated to the same thing everywhere
rik
rikOP•8mo ago
GitHub
website/src/static/scss/main.scss at main · Night-Vision-Discord/we...
Generated website builder. Contribute to Night-Vision-Discord/website development by creating an account on GitHub.
clevermissfox
clevermissfox•8mo ago
And you've given it a few minutes to update the changes ?
rik
rikOP•8mo ago
It appears to be in the live version. I am not sure if my phoen is ignoring it for some reason, btu clearing the cache seems to have no effect.
clevermissfox
clevermissfox•8mo ago
GitHub
GitHub - Night-Vision-Discord/website: Generated website builder
Generated website builder. Contribute to Night-Vision-Discord/website development by creating an account on GitHub.
rik
rikOP•8mo ago
It's showing the same issue in both. which makes sense, since they're usingt he same template and CSS.
clevermissfox
clevermissfox•8mo ago
ah very strange. the dev tools arent showing me any issues, im wondering if its an issue with the way the scss is being compiled or something.
rik
rikOP•8mo ago
it's possible. Let me see what removing the scss compile step does, since I'm not making use of anything it provides.
clevermissfox
clevermissfox•8mo ago
yeah maybe just turn that into a regular css file and see what happens
rik
rikOP•8mo ago
well... the eleventy passthorugh didn't work for it, so no CSS file..
clevermissfox
clevermissfox•8mo ago
i am not familiar with what that means, can you just create a CSS file and link to it in your template?
rik
rikOP•8mo ago
yes, that's what I've just achieved. As an explanation, eleventy is a processor turning markdown into HTML, and inserting it into a template. passthrough is a rule for it to pass through certain things, like the CSS and images, without processing them. we now have the plain .css file, however it's not changing the behaviour on my phone.
clevermissfox
clevermissfox•8mo ago
I just looked at the source file on my phone and although this shouldn't be an issue, humor me and give it a try. Delete the commented out code underneath the media query that declares .pagecontainer as a grid again. I know it's commented out but see if that changes anything as if the comments aren't recognized that's the only thing that could be overriding it (unless there's some specificity issues between your IDs and classes which I haven't looked at yet )
No description
rik
rikOP•8mo ago
that change is on the way up. Initial render has it nicely paginated left and right. A reload makes it overlap weirdly per the previous images. But no snapping to a top/bottom arrangement.
clevermissfox
clevermissfox•8mo ago
This is so weird
rik
rikOP•8mo ago
I'm not ruling out that i or my phone are doing something weird.
clevermissfox
clevermissfox•8mo ago
Something to do with the engine on the android phone, I'll check on iPhone too
rik
rikOP•8mo ago
but if so, I don't know what I'm doing. I'm on Android, but I know there's going to be at least one iPhone user.
clevermissfox
clevermissfox•8mo ago
I am not familiar with eleventy so there may be something with how it or other dependencies work thst I just don't know about Have you used this same process with other sites you've deployed (eleventy snd your dependencies from this project)?
rik
rikOP•8mo ago
nope. But it outputs static HTML at the end, which is what we're looking at.
clevermissfox
clevermissfox•8mo ago
Same two col on iPhone The same code on codepen works and stacks on a phone though so that’s why I’m wondering if it’s something to do with how the deps compile it or how mobile engine renders. The css looks fine and I don’t see any properties that would need a WebKit prefix to stack it But I haven’t gone through the css with a fine tooth comb. The issue is that it’s rendering a grid on mobile when that grid should only be rendered on screens 768+
rik
rikOP•8mo ago
That makes sense to me.
clevermissfox
clevermissfox•8mo ago
Forgot to link the iPhone view
No description
rik
rikOP•8mo ago
It matches up with the experience. What I'm wondering is how we can figure out what chrome on the phones is making the rendering decisions. That's .. also not working right.
clevermissfox
clevermissfox•8mo ago
Nope same two cola Cols And that’s safari so it’s not just a chrome issue
rik
rikOP•8mo ago
i hadn't tested the codepen on my phone ... but it works there.
clevermissfox
clevermissfox•8mo ago
Yep same here
rik
rikOP•8mo ago
I am not getting less confused as we discover more about this.
clevermissfox
clevermissfox•8mo ago
Same. If I were you I may make a new post summarizing this issue (no one is gonna read through this thread ) and see if there are any eleventy experts that may be able to help as I’m about out of tricks
rik
rikOP•8mo ago
I don't think this is an eleventy problem. It generates static HTML, and that HTML is what's uploaded. The codepen is me doing "view-source" and cut-and-pasting that.
b1mind
b1mind•8mo ago
11ty community is super
clevermissfox
clevermissfox•8mo ago
true , I just don’t see why phones aren’t rendering this html and css correctly. It’s like it’s not reading the media query as a media query
b1mind
b1mind•8mo ago
I would ask there
clevermissfox
clevermissfox•8mo ago
Which makes me wonder what’s in the js
rik
rikOP•8mo ago
I would, but it's a preprocessor generating static html. There's no JavaScript on the page. the output of which is behaving differently on our phones, and when pasted in to codepen. I will make a new thread, to give people the chance to not go over the whole backlog
clevermissfox
clevermissfox•8mo ago
I meant the backend as a whole If the behaviour isn't the same even with identical front end code, I would assume sonethings happening in the backend
Want results from more Discord servers?
Add your server