Fluid wrapper

Hi everyone, hope you're doin well! 🙂 I've got a requirements where I should set based on different viewports width, the width of a wrapper container. Here's the list of breakpoints: - From 1440 to 1583 it should adapt to the viewport's width with left and right margin of 64px - From 1584 to 1919 same as before, but with a right and left margin of 72px - From 1920 to 2560 it should be 80% of viewport's width - Above 2560 it should be the 80% of 2560 (2048, basically) I did a first try using media queries to do so, but I wasn't that happy with the result, cause it wasn't that fluid. I was thinking of using calc() for doin the math, but I'm not quite sure. I'm 100% sure that the minimum width of the wrapper is 1312px and the maximum is 2048 (as I said in the last point) Any suggestion? Thanks in advance
16 Replies
Jochem
Jochem•5mo ago
what do you mean fluid? As in, it didn't look great while you were resizing the screen?
FryBlaster
FryBlaster•5mo ago
It's hard to explain, but imagine you're resizing the screen and the container doesn't scale smoothly, but you can clearly see when it's changing
Jochem
Jochem•5mo ago
right. No one does that, other than web developers people just have their browser full screen 99% of the time responsivity doesn't have to be smooth, because no one is going to be changing their viewport size when viewing your site, and even if they do, they're not going to be paying attention to the content while they're resizing
FryBlaster
FryBlaster•5mo ago
Just for example, set a base width of 50px to a box and then set a media queries where you set the width to 100px. When you reach that breakpoint it changes from 50 to 100 immediatly Just to get the idea
Jochem
Jochem•5mo ago
yup, no one is ever going to notice other than other webdevs who are working on your site
FryBlaster
FryBlaster•5mo ago
Yeah, you're right, ahah! Anyway, media queries are the only way to scale the wrapper? Or there's some math I can do with calc() to make things easier? I mean, the easier way was with media queries, but I was curious to know if theres an alternative solution or If I can enhance it
Jochem
Jochem•5mo ago
you can probably use calc and clamp, but you won't be close to the mark a lot of the time if that's important. I'd say a combination is probably the most sane, from 1440-1920 you set a margin that's 64px cause the difference between 64 and 72 is just a designer being pedantic Then from 1920 and up, you set it to 80% clamped to 2560 you can probably even do something like this in a media query over 1920px
width: 80%;
max-width: 2560px;
width: 80%;
max-width: 2560px;
FryBlaster
FryBlaster•5mo ago
Lemme try and see 🙂 Ok, seems fine! I just add a margin-inline: auto to your code, so it's centered
Jochem
Jochem•5mo ago
haha, yeah, good point 🙂 glad it works 🙂
FryBlaster
FryBlaster•5mo ago
Oh wait Almost work Lemme explain Until 1919 wrapper's div is 1791, then on 1920 it shrinks to 1536 Cause we're setting it to 80%, I guess
Jochem
Jochem•5mo ago
that's what the specs request
FryBlaster
FryBlaster•5mo ago
Maybe it's just me being wayy to meticoulus ahah, but yeah, you're right It feels strange tho, but it is what is, I guess. Maybe I'll try to speak with the design team to see if it's good for them
Jochem
Jochem•5mo ago
you could do something like width: clamp(1791px, 80%, 2560px); it'll try to be 80%, but stay between 1791 and 2560px you wouldn't see the width change until much wider than 1920 though, until 80% is higher than 1791px, so around 2240px width
FryBlaster
FryBlaster•5mo ago
This one looks smoother when resizing screen I guess that's fine for the moment. Thanks for the help! 🙂
Jochem
Jochem•5mo ago
no problem 🙂 Remember though, you're probably the only person to ever really resize your site, everyone else just looks at it at a set (but variable) size
FryBlaster
FryBlaster•5mo ago
Nice to know, I'll keep that in mind. Normally I dont put way too emphasy on that, but in this case the client is quite demanding
Want results from more Discord servers?
Add your server
More Posts
Unicode characters broken in Safari?In my navigation, I have been using arrows for my 'a::before' tag. Respectively a::before {content: Firefox CSS IssueSee image 1 and 2. the button doesn't disappear after the card is flipped. HTML ```html <div classGive me feedback and suggestionsI made a design about login component thru figma. I just want some feedback of which i will need to Figma and translating designsHey quick question, I've just recently started learning Figma coming from a fullstack background. DoIf the grid-items had different heights and gap had to be between them is of 20px.In the below codepen, the gap shows too much between, how to make sure that row gap and column gap iShould I use margin-block or traditional margin properties?Recently learned about the margin-block property in CSS, which sets margins based on the writing dirHello, I found this semi-solution to animating <details> and was wondering of the drawbacksI found this blog https://dev.to/neophen/css-only-accordion-with-animations-2d8n, and modified the tMaximize image size, minimize column widthhttps://codesandbox.io/p/sandbox/columns-rsfszr?file=%2Fsrc%2FApp.tsx%3A17%2C50 I am trying to lay [update] done inverted corner not able to achieve animation?i tried to mimic the tutorial "Create a clean, modern navigation with HTML & CSS" without the chromeHow can I make this get smaller as the screen changes sizes?So I created a container with a nice styling I wanted to ask is it possible for the container to dec