首页 > 解决方案 > 当值相同时缩短css

问题描述

如果值相同,如何缩短css?
例如:如何将其合并为一个字符串(与一个auto!important)?

*{width: auto!important}  
*{height: auto!important}

似乎我已经看到了这种可能性(作为一种新奇事物)但找不到。

标签: css

解决方案


您可以将声明缩短为一个:

*{
width: auto!important;
height: auto!important
}

并且您可以使用 css 自定义变量将值缩短为 1,因此每次您想更改值时,请从一个地方进行:

:root{
--foo:auto!important;
}

*{
width:var(--foo);
height: var(--foo);
}

推荐阅读