简体   繁体   English

使用LESS变量的IE8 REM回退

[英]IE8 REM fallback using LESS variables

I need a REM fallback for IE8, there are a ton of mixins that solve this problem by calculating the px equivalent and putting it above the REM style as a fallback, but my REMS are declared as part of a variable and so I don't think this could work. 我需要IE8的REM后备,有大量的mixin通过计算px等效并将其置于REM样式之上作为回退来解决这个问题,但是我的REMS被声明为变量的一部分所以我不这样做认为这可行。

I have tried the polyfill from Chuck Carpenter, for some reason it is not working with my compiled stylesheet. 我已经尝试过Chuck Carpenter的polyfill,因为某些原因它不能使用我编译的样式表。

One other thing I thought of would be to use a conditional stylesheet with em's instead of rems for IE8, but this would need updating and converting every time the normal stylesheet had any changes made so I don't think its manually feasible. 我想到的另一件事是使用带有em的条件样式表而不是IE8的rems,但是每次正常样式表进行任何更改时都需要更新和转换,所以我认为它不是手动可行的。

Another might be to use some sort of conditional method to declare the variables as pixels just for IE8, but I don't think this is supported in LESS. 另一种可能是使用某种条件方法将变量声明为IE8的像素,但我不认为这在LESS中是支持的。

Here is where my REMs are declared: 这是我的REM声明的地方:

@size-gnt: 4.5rem;               /* 72px /16 */
@size-spr: 3rem;                   /* 48px /16 */
@size-big: 2.25rem;             /* 36px /16 */
@size-lrg: 1.75rem;             /* 28px /16 */
@size-med: 1.25rem;        /* 20px /16 */
@size-nml: 1rem;               /* 16px /16 */
@size-sml: 0.6875rem;    /* 11px /16 */
@size-tny: 0.5rem;            /* 8px  /16 */
@baseline: 1.4375rem;    /* 23px /16 */
@1px:      0.0625rem;         /*  1px /16 */

This is an example of when I use them: 这是我使用它们的一个例子:

.spc-pad              {padding: @baseline}  

The polyfill I mentioned: https://github.com/chuckcarpenter/REM-unit-polyfill 我提到的polyfill: https //github.com/chuckcarpenter/REM-unit-polyfill

For a pure CSS/Less solution I guess the most compact method would be to declare all those variables using some "base unit" and then change this base unit (with any suitable method) when compiling IE8 stylesheet, eg: 对于纯CSS / Less解决方案,我想最紧凑的方法是使用一些“基本单元”声明所有这些变量,然后在编译IE8样式表时更改此基本单元(使用任何合适的方法),例如:

@u: 1rem;

@size-gnt: 4.5  * @u;
@size-spr: 3    * @u;
@size-big: 2.25 * @u;
@size-lrg: 1.75 * @u;
// etc.

// then for IE8 just override it with
@u: 16px;

Then for example one way to create that IE8 stylesheet would be to only compile a file like: 然后,例如,创建IE8样式表的一种方法是仅编译如下文件:

@import "your-main-stylesheet.less";
@u: 16px;

That's it. 而已。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM