【问题标题】:css variable and concatenation with "px/em/rem" at the end [duplicate]css变量和最后与“px/em/rem”的连接[重复]
【发布时间】:2021-02-27 20:05:13
【问题描述】:

到目前为止,我的代码如下所示:

@media (min-width: 960px) and (max-width: 1280px){
    :root{
        --vint64-line-height: 1.4;
        --vint64-height: 1.4rem;
    }
}

@media (min-width: 640px) and (max-width: 960px){
    :root{
        --vint64-line-height: 1.3;
        --vint64-height: 1.3rem;
    }
}

@media (max-width: 640px){
    :root{
        --vint64-line-height: 1.2;
        --vint64-height: 1.2rem;
    }
}

我想做类似的事情

--vint64-height: var(--vint64-line-height)rem;

但它不起作用,我很沮丧。

在核心 CSS 中有没有办法将变量值与末尾的“rem”或“px”连接起来以将其分配给另一个值?

【问题讨论】:

    标签: css


    【解决方案1】:

    只需乘以 1 个单位。像这样:

    --vint64-height: calc(var(--vint64-line-height) * 1rem);
    

    【讨论】:

      猜你喜欢
      • 2019-10-11
      • 2016-01-05
      • 1970-01-01
      • 2012-12-06
      • 2011-03-20
      • 2016-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多