Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
简化css表达式_Css - Fatal编程技术网

简化css表达式

简化css表达式,css,Css,可以简化以下CSS表达式吗 .table-width-1 { width:1%; } .table-width-2 { width:2%; } .table-width-3 { width:3%; } .table-width-4 { width:4%; } .table-width-5 { width:5%; } 依此类推,直到100% 谢谢。不,单凭CSS是无法简化的。但是您可以使用一些PHP代码来计算每个类的宽度,如下所示: <style type="t

可以简化以下CSS表达式吗

.table-width-1 {
  width:1%;
}

.table-width-2 {
  width:2%;
}

.table-width-3 {
  width:3%;
}

.table-width-4 {
  width:4%;
}

.table-width-5 {
  width:5%;
}
依此类推,直到100%


谢谢。

不,单凭CSS是无法简化的。但是您可以使用一些PHP代码来计算每个类的宽度,如下所示:

<style type="text/css">
    <?php
        for ($i = 1; $i <= 100; $i++) {
            echo '.table-width-'. $i .' { width: '. $table-width .'%; }';
        }
    ?>
</style>

把它放进你的电脑里。这将生成具有名称的100个CSS类。表宽-1到-100,宽度:1%到100%。在每个类中添加/更改属性也非常容易。这就是我要做的。

使用CSS是不可能的。Sass/SCSS或LESS绝对可能出现问题是什么?如果它太长,只要省略一些元素,如果你不需要它们的话。若您懒得编写它,那个么您可以使用style.php文件,并在服务器上以for循环的形式生成它。对于@Bhavik,可以使用另一个+1!我不知道你可以用js修改$'head'。雅伦·萨姆平永远的一天-谢谢你的回复。