在 calc (css) 中使用 screen.width

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45591449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 12:38:58  来源:igfitidea点击:

Use screen.width inside calc (css)

csswidthscreencalc

提问by Sefean

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

是否有在 calc 中使用 scree.width 的方法?像这样的东西:

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

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

用于@media(max-width: 1024px) 不起作用的具体情况。

回答by Ehsan

100vw = 100% of viewport width

100vw = 视口宽度的 100%

left:calc(250px + 100vw - 1024px)!important;

回答by jberglund

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

您可以使用vw单位来调整与视口宽度相关的事物的大小,所以试试这个:

left: calc(250px + 100vw - 1024px) !important;

回答by Czoka

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

left: calc(250px + 100vw - 1024px)!important;这可能行不通我会这样做:calc(100vw - 774px);(1024 - 250 = 774)

vw- view width

vw- 视图宽度

回答by sKopheK

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

Afaik 没有办法在计算公式中获得“实际视口宽度”:(