36

Is there a was of using screen.width inside calc? Something like this:

 left: calc(250px + screen.width - 1024px)!important;

It is for a concrete situation where the @media(max-width: 1024px) won't work.

Mina S
  • 126
  • 1
  • 11
Sefean
  • 420
  • 1
  • 6
  • 11

4 Answers4

60

100vw = 100% of viewport width

left:calc(250px + 100vw - 1024px)!important;
Ehsan
  • 11,709
  • 3
  • 20
  • 40
6

You can use vw units to size things in relation to viewport width, so try this:

left: calc(250px + 100vw - 1024px) !important;
jberglund
  • 144
  • 3
2

left: calc(250px + 100vw - 1024px)!important; this probably won't work I would do it like this: calc(100vw - 774px); (1024 - 250 = 774)

vw - view width

Czoka
  • 118
  • 3
  • 12
-5

Afaik there's no way how to get "actual viewport width" inside the calc formula :(

sKopheK
  • 143
  • 10
  • 2
    Not even the "vw" unit, meaning "viewport width", as seen in the other three nearly-identical answers? – Linkyu Jun 22 '18 at 14:29
  • managed to get it working in the end, it's just confusing with various units inside of the equations – sKopheK Jun 24 '18 at 21:33