Suggestion for Page Layout and How to Manage It

Hello šŸ‘‹šŸ» I would like to know, - How can I make aside element sticked on the right of the grid? I used position: sticky; but probably going to play with it more later on. - Since I am trying to make it responsive, how can I make it on top of the screen? Should I put section and aside element in a div? (But this time my grid-template-are property won't work well) - Should I use sub-grid? I have never used it before... Therefore, I will keep displaying sections on below of first "section section aside" so you might guess how it would look like. All good! But when it becomes responsive layout as mobile, it becomes:
body {
grid-template-area:
"section"
"aside"
"section";
}
body {
grid-template-area:
"section"
"aside"
"section";
}
Which you can imagine how bad it would look like. What would you recommend to me for this kind of situation?
No description
No description
99 Replies
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
I have tried updating grid-template-area with @media but nothing got update. It did not become "section ... section ... aside".
clevermissfox
clevermissfoxā€¢13mo ago
To make it align to the right of its cell, you can use justify-self: end. If you want it in the top right corner of the cell, also add align-self: start; bottom right corner , align-self: end. Or center of course. You cannot use ā€˜Sectionā€™ ā€˜Asideā€™ ā€˜Sectionā€™ The section cannot be in the first row then skip the middle then also be on the bottom row. To overlay items you have to explicitly declare the line numbers on both. Not sure what you mean by ā€œhow can I make it on top of the screenā€?
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
Sorry, I was meant for main element's first element. Which can be achived with reversed column if I go with flex. But I am using grid, and I am not really familiar with grid so yeah. Makes sense.
clevermissfox
clevermissfoxā€¢13mo ago
You can use order in grid like you can in flex
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
So we can use order on grid too? I thought it is only avaliable for flex
clevermissfox
clevermissfoxā€¢13mo ago
Or you can just declare its grid area as first in the grid Correct
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
Also, isn't that weird? I can not update grid-template-area This is inside my media query
body {
grid-template-areas:
"header header header"
"nav nav nav"
"article article article"
"aside section section"
"footer footer footer";
}
body {
grid-template-areas:
"header header header"
"nav nav nav"
"article article article"
"aside section section"
"footer footer footer";
}
on normal it is section section aside so shouldn't it also re-order its position?
clevermissfox
clevermissfoxā€¢13mo ago
Yes as long as you have given everything their grid-area:
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
I did not
clevermissfox
clevermissfoxā€¢13mo ago
But they canā€™t have the same name , do you have two sections with a grid-area: section ? You have to tell the header itā€™s grid-area: header, footer that itā€™s grid-area:footer
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
When did it:
No description
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
I guess, now I have to re-code everything
clevermissfox
clevermissfoxā€¢13mo ago
Can you share your codepen
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
I was using vsc but lemme share it on codepen https://codepen.io/Neodevils/pen/ExrqpyK this is with areas of course
glutonium
glutoniumā€¢13mo ago
just leaving a side note that justify self is a grid property and align self is a flex property so u cant use them together
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
Adding grid-area: article to main kinda fixes the layout
clevermissfox
clevermissfoxā€¢13mo ago
You have two grids declared. On the grid on your body, you have grid areas declared like aside and section but those are looking at their parent grid, ā€˜mainā€™ which donā€™t have grid-areas defined
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
So, actually grid on body is not required at all
clevermissfox
clevermissfoxā€¢13mo ago
If you replace aside, section etc with ā€˜mainā€™ then give the main a grid-area of main; then in you grid for the main declare the template areas of how you want them to live in that grid, the aside will know where itā€™s grid area is
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
But on main is required
clevermissfox
clevermissfoxā€¢13mo ago
Sure that would work
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
flex, column would work yeah
clevermissfox
clevermissfoxā€¢13mo ago
It will work without flex, as ā€œcolumnā€ is the default behaviour for block items Then on your main grid, give it grid-template-areas: ā€˜Article article articleā€™ ā€˜aside section sectionā€™
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
so using grid on main, with: "section aside" section with big span but how can I achieve that? and on media query I just reverse the grid-template-area with "aside" "section"? Sorry forgot about article but yeah got the point
clevermissfox
clevermissfoxā€¢13mo ago
Section with big span? Iā€™m not sure what you mean ?
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
I want to make section bigger than aside 2x of it
clevermissfox
clevermissfoxā€¢13mo ago
Thatā€™s why you have section spanning two columns And aside is in one
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
I can't make it with only a section word? Can't we make our grid's box bigger than other boxes?
clevermissfox
clevermissfoxā€¢13mo ago
Yes, you already have. Itā€™s spanning 2/3 columns with ā€˜section section asideā€™ You may have to mess with your grid template columns values to Iā€™m not sure what you mean by this , your grid box bigger than what other boxes?
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
So I must use "section section aside"? I am just asking like: "section aside" but section is taking 600px while aside 300px Is that kind of thing possible or not?
clevermissfox
clevermissfoxā€¢13mo ago
Yes it is possible, I was just following your example with the three cold
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
because on flex, we can define flex-grow: 2 and make it bigger than other elements I know, thank you for that. I just wanted to know.
clevermissfox
clevermissfoxā€¢13mo ago
You can say grid-template-columns: 2fr 1fr
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
I add it to main, but can't I play with section or aside instead parent element? It would be better and readable to me if we can resize the element on with it's own properties
clevermissfox
clevermissfoxā€¢13mo ago
And then do grid-template-areas: ā€˜article articleā€™ ā€˜section asideā€™ Which parent element are you talking about ?
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
I will probably do it like that. But pardon me, I am just talking about the "grid-template-columns: 2fr 1fr" you said is for main which is parent element right?
clevermissfox
clevermissfoxā€¢13mo ago
On grid on the main, if you want the first column to be twice the size of the second that is one way to achieve that
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
I am asking "Can't we achieve size of columns on section element directly? Do I have to set it on parent element always?" Oh thank you that's what I wanted to hear šŸ˜…
clevermissfox
clevermissfoxā€¢13mo ago
No you donā€™t have to set it on parent always, could have grid-template-columns: auto auto; and the columns will be the size of the elements within them Then you just assign the grid areas to the grid on main
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
Hmm, I see
clevermissfox
clevermissfoxā€¢13mo ago
grid-template-areas: ā€˜article articleā€™ ā€˜section asideā€™
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
Thanks hart, it was helpful
clevermissfox
clevermissfoxā€¢13mo ago
Happy to help Iā€™ll be offline for a bit but lmk if you get stuck or have any other questions. If youā€™re not aware yet, the grid inspector in the dev tools can be very helpful when learning grid
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
Hart, what about aside element being sticked on the right? Oh okay, sorry sorry Take your time
clevermissfox
clevermissfoxā€¢13mo ago
I thought you wanted it on the right? Column 2?
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
No, no. My first question was about ā€œhow to make aside element stick on the right place even if I scroll downā€
clevermissfox
clevermissfoxā€¢13mo ago
You want it to be position: fixed ?
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
Well, wouldnā€™t it be breaking down grid layout? Yup it does But can fix it All good Not actually working as I wanted but well
clevermissfox
clevermissfoxā€¢13mo ago
I know position absolute works within grid cells but donā€™t remember if position fixed breaks out of the grid or if when scrolling past the end of the main (grid) it stays in its cell. I can play with it later if you havenā€™t achieved what youā€™re intending and update the codepen
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
All good, I will handle them. Thanks Hart. Take your time thumbup
clevermissfox
clevermissfoxā€¢13mo ago
How is it going for you?
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
This is the last thing I have done
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
But sadly, I canā€™t make the aside is having full height of section Sorry, video was made for someone else but yeah still same thing I am not on my laptop right now so I couldnā€™t take a screenshot šŸ˜… The numbers I have added is just a magical numbers Which like I put width 42.5vw for aside > div:nth-of-type(2) element to get same width of aside > div:nth-of-type(1) element. 1. div has a fixed width so its like; image (declared height: 150px, which is width equal to 104px automatically) + 350px child div element which is white box. If I put 100% width on child div, it will simply break cause it has absolute elements inside it (button) and also member images.
clevermissfox
clevermissfoxā€¢13mo ago
When you get on your laptop send me a codepen W your current code. Something that took me a while to learn is if something is in a grid cell, giving it a width percentage makes it that percentage of the cell itā€™s in. You want to use the columns and rows to set the size of the element and donā€™t set the width on the child itself
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
I guess I will just remove grid šŸ„¹ I published my page but the boxes are out of size https://neodevils.github.io/new-minesa/ The page looks so bad on mobile kdfjjdjd
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
Even though I have added @media query, somehow it doesnā€™t work on mobile huh
No description
clevermissfox
clevermissfoxā€¢13mo ago
Iā€™m not on my laptop so I canā€™t inspect and look at your code. If you assigned anything other than a grid-area name to the children like grid-column:2; it will then create an implicit column in the media query. So anything the children have has to be reassigned like grid-column: initial; Donā€™t know if thatā€™s the issue but thatā€™s the first thing that comes to mind if grid isnā€™t doing it for you within the media-query. What is it youā€™re struggling with ? Just laying everything out the way you want?
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
Mainā€™s margin is stopping after a width. If you check the link you can see elementsā€™ width kinda breaking its boxes
clevermissfox
clevermissfoxā€¢13mo ago
Especially when using grid you donā€™t need to set a width , you use the template columns to set the elements width and they take on the size of the cell theyā€™re assigned to. When you say ā€œbreaking its boxesā€, do you mean the grid cells? Or the grid as a whole? Or do you mean its overflowing as I see on mobile so im looking at it. looks great on desktop! fyi
grid-column: span 1
grid-column: span 1
is the default so you dont need to declare that. you have redeclared place-content: center in your media query which is contributing to the content being cut off Its also being cut off because there is nothing that is making the content smaller on mobile, you dont have a clamp on your font-size so the content is just taking up more space then there is so its getting cut off. or side-scrolling Then when your font-size is fluid to the size of the viewport, you can set your margin and padding in ems instead of using a clamp on margin
clevermissfox
clevermissfoxā€¢13mo ago
So get some clamps set up and apply them to your text sizes. utopia is a good one that will spit out several scales that you can easily apply to your body font-size, h1, h2, h3, etc and that should help https://utopia.fyi/type/calculator?c=320,18,1.2,1240,20,1.25,5,2,&s=0.75%7C0.5%7C0.25,1.5%7C2%7C3%7C4%7C6,s-l&g=s,l,xl,12
Utopia
Fluid type scale calculator
Fluid responsive design
clevermissfox
clevermissfoxā€¢13mo ago
the other issue may be your images like this one aside div.guild-container > img setting height and width esp in pixels means its going to take up that much space no matter what. fixed heights are a big no no. If you absolutely need a height, use min-height so you dont get overflow Aspect-ratio is also a new property that is helpful.
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
Well, width has been settled on aside element (white box) cause it is an absolute element so yeah. I gotta make it a normal element with auto width so grid would work normally Ig its causing the all issues xd
clevermissfox
clevermissfoxā€¢13mo ago
You gave it a width or you let it fill up the column and made that grid col the width you want it to be?
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
I just set a fixed width Since aside had two elements and one of them absolute element I had to set a fixed width But I just figured out a few days ago, I can just make that aside is div box with flex space-between with images inside the div Then a div inside of it which is second row of that element And it would get width auto which would work perfectly
clevermissfox
clevermissfoxā€¢13mo ago
The width should be set with the padding and content. If an element is absolute make up the width of that with content and padding. If you absolutely have to set a width make sure to use fluid units like percentages or viewport units . When container queryā€™s are fully supported itā€™s gonna be a game changer. Still recommend using clamp for the text with padding/margin in ems
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
Working with absolute elements is like hell
clevermissfox
clevermissfoxā€¢13mo ago
Itā€™s true! Grid makes it a lot easier though
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
Yeah, I will use clamp for texts but i still didnā€™t figure it out well Isnā€™t clamp() like min-size, increase-when-on-this-width/height, max-size?
clevermissfox
clevermissfoxā€¢13mo ago
You set the values through that website then assign the body size to body -> font size. Then for h1 use the largest, h2, the second largest etc.
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
oh So
clevermissfox
clevermissfoxā€¢13mo ago
Kinda the second value in the clamp is the growth factor, itā€™s like the preferred size
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
body { font-size: 1em; } h1 { font-size: clamp(2.5em, ???, 5em); } I must declare it on body? So if I put 3em inside of clamp on h1, how will exactly it work? I actually want to use pt for fonts think but letā€™s see
clevermissfox
clevermissfoxā€¢13mo ago
I linked that utopia tool because it spits out a bunch of values you can use as custom properties in the root
:root{
ā€”fs-lg: font-size: clamp(1.75rem, 1.3523rem + 1.5909vw, 2.625rem);

ā€”fs-body: clamp(1rem, 0.7727rem + 0.9091vw, 1.5rem);
}
Body {
font-size: var(ā€”fs-body)
}
h1{
font-size: var(ā€”fs-lg);
padding:1em
}
:root{
ā€”fs-lg: font-size: clamp(1.75rem, 1.3523rem + 1.5909vw, 2.625rem);

ā€”fs-body: clamp(1rem, 0.7727rem + 0.9091vw, 1.5rem);
}
Body {
font-size: var(ā€”fs-body)
}
h1{
font-size: var(ā€”fs-lg);
padding:1em
}
No not ems on the clamp, use the clamp as the font size then use end for padding and margins so they shrink and grow with the font size
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
I actually still confuse on a part. How can we set rootā€™s rem value to different value? Like 1rem = 16px but it can be changed?
clevermissfox
clevermissfoxā€¢13mo ago
Nonono pts are for print design. Using px or pt for font size is not accessible
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
Oh, i use pt for designing stuffs so yeah šŸ˜…
clevermissfox
clevermissfoxā€¢13mo ago
Itā€™s not setting the roots font size, itā€™s storing custom properties. The root is still 16px. I saw you were using custom properties so I thought you were familiar. Setting the pages font size comes from the body
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
No I am familiar with it but that was always been a question in my mind xd
clevermissfox
clevermissfoxā€¢13mo ago
Just donā€™t use them for web graphics or websites. Pts are okay in print design because itā€™s being printed out.
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
I heard that we can change the rootā€™s value so I wanted to ask ā€œhow?ā€
clevermissfox
clevermissfoxā€¢13mo ago
Root is just storing the properties so they are inherited down but itā€™s still getting itā€™s font size 1rem from the browser (16px).
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
Then whatā€™s the difference between 1rem and 1em?
clevermissfox
clevermissfoxā€¢13mo ago
Some people set :root {font-size: 62.5%} which makes 1rem = 10px
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
Oh Thatā€™s what I was asking for Thank you šŸ˜‚ We can change rem but not em right?
clevermissfox
clevermissfoxā€¢13mo ago
Setting ems on font-sizes makes a cascading effect. So if you set body{ font-size: 16px } .container {font-size: 1.5em } then the font size in the container becomes 32px. .container h1 {font-size: 1em} now the h1 is 32px. Itā€™s kinda hard to explain the cascade but the root sets the rem , defaults to 16px from the browser but for font-sizes end cascade from the parent
Jochem
Jochemā€¢13mo ago
You can but you shouldn't. It's bad practice, and has a negative effect on accessibility
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
I see
clevermissfox
clevermissfoxā€¢13mo ago
Using padding and margins with ems looks at the elements OWN fontsize not the parent so itā€™s able to be fluid when using clamp
Jochem
Jochemā€¢13mo ago
if you absolutely have to, set it using % like this, but never ever under any circumstance set it using px on the root or html elements. It effectively tells people with vision problems to just fuck off and not use your site, because it doesn't let them adjust the font size. My advice is to just get used to 0.125rem being 2px, the math from there is pretty simple and easy enough to memorize
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
Brb
clevermissfox
clevermissfoxā€¢13mo ago
This will prob explain better than I can typing on mobile https://youtu.be/_-aDOAMmDHI?si=y4Szux3IB2S0NNaE
Kevin Powell
YouTube
CSS em and rem explained #CSS #responsive
A look at the CSS units EM and REM, how they work and when you might want to use one over the other! First I take a look at some basic examples of both ems and rems, then move onto some more interesting things with buttons and a call to action, as well how we can take advantage of both the em and rem with media queries. The way the em unit is ...
clevermissfox
clevermissfoxā€¢13mo ago
And setting font sizes in px and pts is inaccessible because it doesnā€™t honor the user style sheet settings or ability to zoom, do I have that correct ?
Jochem
Jochemā€¢13mo ago
yes, exactly
clevermissfox
clevermissfoxā€¢13mo ago
Same with using viewport units as font sizes too
Jochem
Jochemā€¢13mo ago
there's ways around that one (like including a rem in calc) but yeah
clevermissfox
clevermissfoxā€¢13mo ago
I love clamp it makes life so much easier Trying to talk Op into it haha ā€˜Em is inherited from parent, REM is inherited from :root to put it simply Ems cascade so if body has font-size: 16px, then the next child .container uses 1em, at this point 1em=16px. Then inside of there .container-child, if you use 1.5em, font size is now 24px. Go inside that container .container-grandchild and use 1em, 1em now is equal to 24px.
body (fs:16px)->
.container (fs:1em[16px])->
.container-child(fs:1.5em[24px])->
.container-grandchild (fs:1em[24px])
body (fs:16px)->
.container (fs:1em[16px])->
.container-child(fs:1.5em[24px])->
.container-grandchild (fs:1em[24px])
While youā€™re learning you could just use
:root{
font-size: clamp(1rem, 0.8864rem + 0.4545vw, 1.25rem);
}
body { font-size: 1rem; }
h1 { font-size: 2.5rem }
h2 { font-size: 2.25rem}
h3 { font-size: 2rem;}
:root{
font-size: clamp(1rem, 0.8864rem + 0.4545vw, 1.25rem);
}
body { font-size: 1rem; }
h1 { font-size: 2.5rem }
h2 { font-size: 2.25rem}
h3 { font-size: 2rem;}
Just donā€™t set a font size on the root in production. Use the clamp in several custom properties then assign those to each text element. I donā€™t want to confuse you with a list of clamp custom properties. KPs videos will help too So to sum up what we learned about responsive coding: Set up custom properties with clamp, assign those as your font sizes `body {font-size: var(ā€”fs-body);} h1 { font-size: var(ā€”fs-lg);} .small{font-size : var(ā€”fs-sm);} ` Use ems for padding and margins and gap whenever possible Never set font sizes in pixels or pts (or any other fixed size) when coding for the web. This makes it inaccessible for the user. If not using clamp, use rems. Never set fixed heights (!!!!) , avoid setting any kind of height; aspect-ratio can help. try to avoid setting any widths (the padding+content should make up the elements size) and if you must, make them min-widths or widths with responsive units like % , vw etc. when using grid, set the size of the cell and the element will fill it up. grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr) ); On grid, you donā€™t have to declare grid-column: span 1; , thatā€™s the default. The less properties you set on the children, the less properties you need to reset or change in a media query. Itā€™s very rare for me to have to write a media query these days! All the tools are available to make it perfectly responsive and looking good!
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
Okay so Thanks for the website you sent, I will use it when I have free internet cause it is limited for now šŸ˜… I will play with it later. Although grid would be better than flex to me in my webpage, but unfortunately that aside element made me lazy so I just hidden it after making all my grids into flex boxā€¦ But so far, the website still working as I expected. Only one thing is missing, which is clamping and resizing the image sizes. With absolute item on top of it (for user:neo > album-info) šŸ„ŗ https://neodevils.github.io/new-minesa/ I just have to play with padding and margin for the boxes, and itā€™s all good to go
clevermissfox
clevermissfoxā€¢13mo ago
Images probably donā€™t need clamp , they should resize with the viewport/their container. Just opened on mobile and the images look good to me!
NeĻƒč®ø
NeĻƒč®øOPā€¢13mo ago
Thank you šŸ™
Want results from more Discord servers?
Add your server