Jump to content

exponential vw (viewport width) calculations?


ChenXiu

Recommended Posts

Given the following css rule:
body { margin: 0 100px; }

I then want the margin to start shrinking at a viewport width of 600px:
@media screen and (max-width: 600px) {
body { margin: 0 8.333vw; }
}

The Challenge:
The aforementioned css rule causes the margin to become zero only when the viewport width reaches zero...
Is there a way to cause the margin to smoothly become zero when the viewport reaches, say, 400px?

It appears the only way to do this is by using chain of several diminishing @media queries.
(And, using "transition: ease all .2s" to liquify the transition points.)

Is there a fancy css rule using calc (along with exponents perhaps) that can accomplish this? (I've tried doing things "viewport squared," but it appears you cannot multiply viewports times itself.)

Any ideas would be appreciated.

 

 

 

Link to comment
Share on other sites

Whether it's padding or margin in this case doesn't really matter - the question could still be valid and of use to others. If you could explain a bit more fully what it is you're after and what you've tried we can all work to come to a solution that works regardless the target attribute.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.