sass 将 px 转换为 vw

Nig*_*ker 0 css function sass

我找到了一个关于如何编写将像素转换为 vw 的函数的教程:

@function get-vw($target) { 
  $vw-context: (1000*.01) * 1px;
  @return ($target/$vw-context) * 1vw;
}
Run Code Online (Sandbox Code Playgroud)

教程中的用法:

.headline {
  font-size: get-vw(72px);
}
Run Code Online (Sandbox Code Playgroud)

但是当我像它所解释的那样使用它时,我的浏览器没有返回任何结果:

字体大小:get-vw(44px); 属性值无效

因为我现在不需要学习 sass,但只需要将 px 转换为 vw 的方法,有人可以帮助我完成这项工作吗?

小智 5

@function vw($px-vw, $base-vw: 1292px)    
  @return ($px-vw * 100vw) / $base-vw

.container
font-size: vw(16px)
Run Code Online (Sandbox Code Playgroud)