代码之家  ›  专栏  ›  技术社区  ›  Johan

IE11中的计算百分比

  •  1
  • Johan  · 技术社区  · 5 年前

    有什么方法可以制作css calc 函数在ie11中的偏移量如下?

    这在IE11中不起作用:

    div:nth-child(1) {
      background: hsl(114.54545, 44%, calc(55.88235% * 1.1));
    }
    

    静态百分比:

    div:nth-child(2) {
      background: hsl(114.54545, 44%, 55.88235%);
    }
    

    https://jsfiddle.net/d5hoe102/1/

    1 回复  |  直到 5 年前
        1
  •  2
  •   Temani Afif    5 年前

    您可以尝试使用额外的白色层来近似它,以增加不需要的亮度 calc()

    div:nth-child(1) {
      background: hsl(114.54545, 44%, calc(55.88235% * 1.1));
    }
    
    div:nth-child(2) {
      background: hsl(114.54545, 44%, 55.88235%);
      position:relative;
      z-index:0;
    }
    div:nth-child(2):before {
     content:"";
     position:absolute;
     z-index:-1;
     top:0;
     left:0;
     right:0;
     bottom:0;
     background:rgba(255,255,255,0.1); 
    }
    <div>calc</div>
    <div>static</div>

    您也可以使用多个背景:

    div:nth-child(1) {
      background: hsl(114.54545, 44%, calc(55.88235% * 1.1));
    }
    
    div:nth-child(2) {
      background: 
        linear-gradient(rgba(255,255,255,0.1),rgba(255,255,255,0.1)),
        hsl(114.54545, 44%, 55.88235%); 
    }
    <div>计算<div>
    <div>静态<div>