Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.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
Html CSS类模板?_Html_Css - Fatal编程技术网

Html CSS类模板?

Html CSS类模板?,html,css,Html,Css,有没有办法在CSS中创建一个可以在多个类中使用的“模板”类?例如: .tile { position: absolute; background: #ededed; width: 100px; padding: 10px; margin: 5px; } .tileA { class: tile; height: 100px; } .tileB { class: tile; height: 200px; } 只要这样做:

有没有办法在CSS中创建一个可以在多个类中使用的“模板”类?例如:

.tile {
    position: absolute;
    background: #ededed;
    width: 100px;
    padding: 10px;
    margin: 5px;
}

.tileA {
    class: tile;
    height: 100px;
}

.tileB {
    class: tile;
    height: 200px;
}
只要这样做:

.tile, .tileA, .tileB {
    position: absolute;
    background: #ededed;
    width: 100px;
    padding: 10px;
    margin: 5px;
}

.tileA {
    height: 100px;
}

.tileB {
    height: 200px;
}
只要这样做:

.tile, .tileA, .tileB {
    position: absolute;
    background: #ededed;
    width: 100px;
    padding: 10px;
    margin: 5px;
}

.tileA {
    height: 100px;
}

.tileB {
    height: 200px;
}

有效地使用类。可以为元素提供多个类

您可以使用诸如
LESS
SASS
之类的预处理器

尝试:

HTML:


有效地使用类。可以为元素提供多个类

您可以使用诸如
LESS
SASS
之类的预处理器

尝试:

HTML:


查看CSS预处理器,如和。我知道SASS可以满足您的需求。

查看CSS预处理器,如和。我知道SASS会满足您的要求。

您不能使用CSS继承,但正如前面演示的,您可以将“子类”分配给基类定义,请参见:

还有一篇关于面向对象程序员的CSS和继承的很好的文章:


有一些第三方工具可以做类似的事情(我认为很流行),但基本上纯CSS不支持继承。

您不能使用CSS继承,但正如前面演示的,您可以将“子类”分配给基类定义,请参见:

还有一篇关于面向对象程序员的CSS和继承的很好的文章:


有第三方工具可以做类似的事情(我相信很流行),但基本上纯CSS不支持继承。

不是经典编程意义上的。至少,不是普通CSS

不过,有两种方法可以做类似的事情:

  • 在元素上使用多个类,例如
    class=“tile tileA”
  • 使用预处理器(例如)并使用:


不是在经典编程的意义上,不。至少,不是用普通的CSS

不过,有两种方法可以做类似的事情:

  • 在元素上使用多个类,例如
    class=“tile tileA”
  • 使用预处理器(例如)并使用:

这将是可能的和

这就是Sass的目的,试试看,如果有和

这就是Sass的作用,试试看

属性选择器在这里可以很好地工作 这会将css应用于所有查看以下内容的
.tile
类:

属性选择器在这里可以很好地工作 这会将css应用于所有查看以下内容的
.tile
类:


不,无论如何不在css中不,无论如何不在css中我不知道为什么,但是我的代码-arg中的标记被破坏了。我不知道为什么,但是我的代码-arg中的标记被破坏了。
.tile {
    position: absolute;
    background: #ededed;
    width: 100px;
    padding: 10px;
    margin: 5px;
}

.tileA {
    height: 100px;
}

.tileB {
    height: 200px;
}
%tile { 
    ... 
 }
.tileA  {
   @extend %tile;
   height: 100px;
}
.tileB {
   @extend %tile;
   height:200px;
}
[class^='tile'], /* selects if any "tile" class is the first class */
[class*=' tile'] /* selects if any later class starting with "tile" */
{
    position: absolute;
    background: #ededed;
    width: 100px;
    padding: 10px;
    margin: 5px;
}

.tileA {
    height: 100px;
}

.tileB {
    height: 200px;
}