Figuring out the measurements for your site layout

When deciding on a site layout, what decisions help you decide on what units to use like pixels vs percentages vs viewport vs... etc. Just curious because I'd like to build a simple layout as place holders but I get stuck on what units to use in what situation and positioning elements where I want them. I can get a very basic layout on paper and using background colored attributes but get stuck on units to use. Hope to get some great feedback 🙂
80 Replies
b1mind
b1mind•2y ago
The less you define the better. Please avoid ViewPort units when starting out, because they are not some magic responsive unit like some think lol Try for Intrinsic designs/layout that don't rely too much on constraints of unit values.
MD
MD•2y ago
what units are best to get started with? I'm hoping to get to responsive
b1mind
b1mind•2y ago
The ones you don't define, for layout let your content determine size. The less you define widths/heights the more responsive it is. when you do use min/max to help. I still use pixels depending on device/need. Rem will help you base off the root font size if you need it to change when user/os changes it.
MD
MD•2y ago
what about em?
b1mind
b1mind•2y ago
Otherwise try to use %'s or again nothing at all.
MD
MD•2y ago
this is my designs for that project I was working on
b1mind
b1mind•2y ago
I don't really use em much. It cascades oddly. I have gotten in the habit of using them for media queries but thats really it.
MD
MD•2y ago
rem a better choice?
b1mind
b1mind•2y ago
Always "it depends" Understanding what it does and how it works is more important cause its based on root font size So if I wanted it to change with the root font then I would use it. if not I'd use px No overall "use this unit always" kinda thing
MD
MD•2y ago
messing around with this is helping some
b1mind
b1mind•2y ago
Rather "stay away from viewPort units" they broken (jp but they have caveats and might not be what you think they are, best to learn why/when to use them) Def don't use them like I see lots of people setting w/h all the time. >.>;;
MD
MD•2y ago
im doing grid and flex examples
MD
MD•2y ago
MD
MD•2y ago
here it is mobile
MD
MD•2y ago
b1mind
b1mind•2y ago
right on 😄
MD
MD•2y ago
granted the examples are giving you units but im not sure when I make own how to break these things up. I think once I grasp that and positioning, the rest will get easier
b1mind
b1mind•2y ago
side note we are getting better viewport units soon, and chrome now lets you tell overlay (keyboard/bars) to not change veiwport
MD
MD•2y ago
im just dumb 😄 oh really they say viewport is easy to work with
b1mind
b1mind•2y ago
who is they? cause "they" don't do enough testing lol
MD
MD•2y ago
web site articles from devs like devs.to css tricks
b1mind
b1mind•2y ago
link me? I just see lots of mistakes from begineers trying to use Viewport vh/vw not even vmin/max really poorly. When what they really want is % its the actual viewport too so on mobile it causes lots of headaches, and ignores scrollbars
MD
MD•2y ago
b1mind
b1mind•2y ago
I mean that explains it well but I don't see them saying use them all over. Or that they are "easy". very specific use case even, as a break out unit. (which is a legit use for viewport units)
MD
MD•2y ago
hmm true
b1mind
b1mind•2y ago
😉
MD
MD•2y ago
what helps you breaking down a layout into where you want to place things and getting it to work right?
b1mind
b1mind•2y ago
grid/flex, again the less you define widths/heights the better (most the time) for responsive layouts.
MD
MD•2y ago
some friends suggested I use grid for the pictures layout on my voting app as they said "perfect" example of needing grid i keep messing with it but cant get it how I want it yeah my goal is responsive layouts like I still get confused on position absolute and relative when to use which
ghostmonkey
ghostmonkey•2y ago
Are you familiar with Figma? It might be easier to use that for your initial designs rather than pen/paper
MD
MD•2y ago
ive seen it just dont think its free but I heard it does a really good job
b1mind
b1mind•2y ago
I wireframe on paper, then goto figma (yes its free.... for now )
MD
MD•2y ago
I just use excalidraw I used to use dreamweaver or illustrator in the early days
ghostmonkey
ghostmonkey•2y ago
It’s free at the moment, you can check it out
MD
MD•2y ago
they got 3 figma and 3 figjam files for free how does figma help with the css?
ghostmonkey
ghostmonkey•2y ago
You can make unlimited drafts on the free plan which is all you need it for
MD
MD•2y ago
does it help with the css?
ghostmonkey
ghostmonkey•2y ago
It’s just for making quick designs without having to write code. It does make the css easier when you get there though because you are just recreating what you already designed so you focus on the code without distraction
MD
MD•2y ago
ah did you see my png of layouts form excali? *from granted I can make anything as fancy as figma
ghostmonkey
ghostmonkey•2y ago
Yes hehe, that’s why I suggested figma. 🙂
MD
MD•2y ago
yeah im terrible at design
b1mind
b1mind•2y ago
Err wrong link
MD
MD•2y ago
lately my memory getting rough with trying to remember all this css stuff and react and then keeping up with what I already know and trying to handle family's stuff lol
b1mind
b1mind•2y ago
Joy Of Code
Design For Developers
Learn enough visual design to be dangerous with actual tips instead of theory.
MD
MD•2y ago
oh is it important to always have
*{
box-sizing: border-box;
}
*{
box-sizing: border-box;
}
b1mind
b1mind•2y ago
Its more important to understand why, but yea most the time you want it. Learn about CSS box model in general
MD
MD•2y ago
thanks! 🙂 I remember we had to have css reset stuff guessing that's one
13eck
13eck•2y ago
A bit late to the convo, but here's my 2¢: • Font size should use rem b/c it respects the user's chosen base font size (and em gets wonky if you nest it) • If you do a variable font size (using clamp() the first and third number should always be in rem, the middle number needs rem + viewport unit • Padding/margin should be in em, because larger font size needs more breathing room • The content should decide the width/height, but if the main content is text, a good max width is 60ch, since ch is the width of the 0 character of the current font face and size (and ~66 characters per line is often cited as the "ideal" line length) • Borders and border radius can be in px, since it's all display and not actually relavent to the overall point of the page • Media queries should be in rem or em b/c you should be changing layout based on content, and content is usually determined by font size Of course this is a bit of a simplification, but a good starting point. And with everything, once you know the why of the rules can you start to break them with purpose (and not on accident).
b1mind
b1mind•2y ago
media queries do not change when using rem or em. Least in all my tests it was a flat number even if root fontsize is changed. Its a flat px number period. The reason people say to use EM is because of the difference the way browsers behave using PX
b1mind
b1mind•2y ago
PX, EM or REM Media Queries? | Zell Liew
Have you wondered if you should use px, em or rem for media queries? I had the same question too, and I never figured it out, not till now. When I first created the mappy-breakpoint library, I used rem units. Then [after a
MD
MD•2y ago
is sitting font size on your html attribute in your css file using percentages a good idea?
b1mind
b1mind•2y ago
You will find some people that will defend using the whole 62.5% font size on html but yea nope... don't imo Its going to make life easy for a px to rem conversion but from what I know its still bad for User font size which is the whole reason you use rem.
13eck
13eck•2y ago
["Yeah, yeah, your scientists were so preoccupied with whether they could, they didn't stop to think if they should"] https://tenor.com/tOxp.gif
Tenor
13eck
13eck•2y ago
62.5% font size is 1100% to make life "easier" for devs and literally shits on users who change their default font size. Don't ever do it unless you really want to alienate users who change their font size
MD
MD•2y ago
What is the best approach?
13eck
13eck•2y ago
The best approach is what b1 said in the first response:
The less you define the better. Please avoid ViewPort units when starting out, because they are not some magic responsive unit like some think lol
MD
MD•2y ago
Height at 100% seems useful
13eck
13eck•2y ago
Seems, sure. But what does it do? Not a whole lot % is percent of parent container, and for height elements only take up as much room as they need to by default, so unless you're setting a specific height on the parent container the parent container's height is the same height as that of all the content's height combined…which is the same as not setting height: 100% lol
MD
MD•2y ago
What do you put in your html selector typically?
13eck
13eck•2y ago
Typically nothing
MD
MD•2y ago
I know root is for variables typically
b1mind
b1mind•2y ago
no you have to use height: 100% on html or you can't use percent of properly on the way down until you have a set a strict height to another parent to use % off of
13eck
13eck•2y ago
::root for global variables, yes. Then I do my font-size trick on body along with margin: 0;. After that I only add things that I need to specifically change using as less-specific selectors as I can. Usually with a class on the container element then element selectors for everything else Oh, and *, *::before, *::after {box-sizing: border-box;} as the very first item
MD
MD•2y ago
Can you explain those value choices for your clamp It is pretty nice using rem vmin
13eck
13eck•2y ago
Yeah, sure.
::root {
--1rem: clamp(1rem, 0.875rem + 1.5vmin, 2rem);
}

body {
font-size: var(--1rem);
}
::root {
--1rem: clamp(1rem, 0.875rem + 1.5vmin, 2rem);
}

body {
font-size: var(--1rem);
}
So, clamp takes three numbers, the minimum value, the ideal value, and the maximum value. The result of the clamp will be the ideal value (the middle), unless it's smaller than the min or larger than the max. So with my starter template above, the font size will be 0.875rem + 1.5% of the viewport's width or height (which ever is smaller, due to vmin). But if that number is smaller than 1rem it'll be 1rem, and if that number is larger than 2rem it'll be 2rem. As an example, say the user doesn't change their default font size, so 1rem is 16px. And let's also assume the viewport is 800px x 600px. • 1.5vmin = 1.5% x 600 (0.015 * 600) = 9px • 0.875rem = 0.875 * 16 = 14px That sets the font size to 23px. That's larger than 1rem (16px) and smaller than 2rem (32px) so that's our font size Of course you're free to mess around with both the ideal and max values. You may want a smaller growth, so you'd use 0.75vmin or something. Or you want the max to be a bit smaller, so you'd use 1.5rem.
MD
MD•2y ago
This is really good breakdown of clamp. I dont see it used often
13eck
13eck•2y ago
I love clamp() and min(). They're both super-useful CSS functions
MD
MD•2y ago
That 0.875 rem is 14px Nice
13eck
13eck•2y ago
I like to stick to nice fractions. 0.875 is 7/8 Because 1rem is normally 16px you can use any */8 fraction and it'll be a whole number
MD
MD•2y ago
I should learn those fractions like when Kevin explained using numbers in his color vars Yeah 16/8 is 2
13eck
13eck•2y ago
8/8 = 16 7/8 = 14 6/8 = 12 5/8 = 10 4/8 = 8 3/8 = 6 2/8 = 4 1/8 = 2
MD
MD•2y ago
That's actually really smart for responsive font sizes Mobile to desktop
13eck
13eck•2y ago
I usually use 2/8 (1/4), 4/8 (1/2), 6/8 (3/4), 7/8, 9/8 (1.25), 10/8 (1.5), and 16/8 (2) as my default sizing scheme. 7 sizes to rule them all, and in the darkness bind them. Or something I don't make random and variable different sizing for things like line height, margin, padding, etc. I have a solid scale system and only use those numbers. Set 'em up as variable on ::root and boom! You're off to the races
MD
MD•2y ago
How do you handle adaptive vs responsive layouts so your screen changes don't like snap change but are more fluid
13eck
13eck•2y ago
First thing is the fluid font size I showed above. Combine that with rem- or em-based padding/margin and you're over half-way there After that, continue to use relative units like em, rem, viewport, ch, etc for sizing things and you can use some basic breakpoints to change things like flex-direction (going from column to row, for example) and grid min/max. And be sure to use em/rem for your breakpoints and not px. Once you get comfortable with CSS' other, more esoteric, rules you can bypass breakpoints almost entirely!
13eck
13eck•2y ago
For example, leveraging some flexbox tricks you can do a sidebar swap without any breakpoints: https://every-layout.dev/layouts/sidebar/
MD
MD•2y ago
I like this link
13eck
13eck•2y ago
(among other cool ideas) Every layout is amazing. I love it so much and is well worth the price of admission IMO
MD
MD•2y ago
I like layout breakdowns and seeing why certain values are used with explanation
Want results from more Discord servers?
Add your server