Css 在另一个样式中包含样式

Css 在另一个样式中包含样式,css,Css,所以我一直在思考这个问题,我认为这是不存在的。我也明白我的逻辑与样式表试图适应的内容是对立的,但让我们试一试: 以以下为例: // Example "template style" .blue_bold { color: blue; font-weight: bold; /* other styles can go here */ } 假设我想把它添加到我的页脚,我会在我的HTML中: <div class="blue_bold" id="fo

所以我一直在思考这个问题,我认为这是不存在的。我也明白我的逻辑与样式表试图适应的内容是对立的,但让我们试一试:

以以下为例:

 // Example "template style"
 .blue_bold {
      color: blue;
      font-weight: bold;
      /* other styles can go here */
 }
假设我想把它添加到我的页脚,我会在我的HTML中:

 <div class="blue_bold" id="footer">
      // Content goes here
 </div>
这样我就可以通过创建“基本样式”来最小化代码,然后将这些样式附加到样式表中的各个样式?这同样只是一个问题,不是我想实现的东西,但我认为,鉴于上述情况,对于使用say品牌指南文档并希望将特定样式附加到单个样式的人来说,这将是一个“很好的选择”,而无需使用html


有什么想法吗?这是否存在

纯CSS无法实现这一点。您需要使用或生成CSS

此处的语法示例:

更少

.blue_bold {
    color: blue;
    font-weight: bold;
}
#navigation, 
#footer {
    .blue_bold;
}
.blue_bold {
    color: blue;
    font-weight: bold;
}
#navigation, 
#footer {
    @extend .blue_bold;
}
SCSS

.blue_bold {
    color: blue;
    font-weight: bold;
}
#navigation, 
#footer {
    .blue_bold;
}
.blue_bold {
    color: blue;
    font-weight: bold;
}
#navigation, 
#footer {
    @extend .blue_bold;
}

你需要看一看sass或更少,它们是你最好的选择

无礼


less

您可以使用sass或less,但更基本的解决方法是在css中列出元素,如下所示:

#navigation,
#footer,
.some-other-element,
.another-element
{
      // css styles go here that you want to apply to each element listed above
}

看不到任何好处。你要的不是标准的CSS。 您可以使用class
blue\u bold

.blue_bold {
     color: blue;
     font-weight: bold;
     /* other styles can go here */
}
这个街区

<div class="blue_bold" id="navigation"></div>

除非被覆盖,否则将使用从.blue_bold开始的所有内容。有什么不对吗?

请参见:当您可以通过简单CSS实现相同的功能时,他为什么要使用其他JavaScript库?因为这是一个问题:“对于通过类或样式声明它,是否无法将样式“附加”到我的样式表中的另一个样式?”。PS:SASS和LESS是什么时候成为JavaScript库的?据我所知,LESS使用LESS.js来“解析”.LESS文件。这不是问题。这已经是Mautitz Swanepoel所拥有的,他恰恰希望避免在HTML文件中使用
blue_bold
类。没有解决方案,是的,LESS或SASS都不是解决方案。真正的解决方案将是在下一版本的css中使用SASS或更少的语法。这是我没有想到的最具逻辑性的解决方法:)我能看到的唯一“缺点”是,如果我遵循这一点,并在以后重新声明页脚,人为错误可能是为2个元素添加颜色,所以实际上,我在同一个样式表中声明了两次或多次footer,以后可能会变成***故障排除:),但这是个好主意
#navigation, #footer {
     background: black;
     color: red;
}