2016-08-27 76 views
0

我想要嵌套类和普通类使用相同的属性。例如...SASS普通类和嵌套类具有相同的属性

.menu-container ul li.run a, 
body[data-primary-tags*='run'] { 
    .article-overview-header, 
    .article-detail-header-strip, 
    .article-detail-sub-header { 
     background-color: $run; 
    } 
} 

显然,这是行不通的,但有没有办法有li.run a和嵌套类具有相同的背景颜色?

+0

你为什么说“这不行”?例如,如果将'$ run'变量设置为“red”,则会得到:'.menu-container ul li.run .article-overview-header, .menu-container ul li.run a .article-detail - 数据主标签* ='运行'] .article-overview-header, 主体[数据 - 主标签* ='运行']标签 - 主标签条, 。主标签* ='运行'] .article-detail-header-strip, body [data-primary-tags * ='run'] .article-detail-sub-header {background_color:red; “你期望什么CSS? – blonfu

回答

1

使用SASS你可以做@extend这样的事情:

.my-special-class 
    background-color: $run 

.menu-container ul li.run a, 
body[data-primary-tags*='run'] 
    @extend .my-special-class 

    .article-overview-header, 
    .article-detail-header-strip, 
    .article-detail-sub-header 
     @extend .my-special-class 

为了实现在纯CSS你应该让你选择的父类的背景颜色,让嵌套类继承了值。尽管他们需要成为第一代孩子才能继承适当的价值。

+0

感谢您的支持。我认为这可能是目前唯一的选择。 –

相关问题