这是我的设置:
文件关系
home.php <---styles---- _layout.scss
|
imports
|
v
animation.html <---styles---- _animation.scsshome.php -用于勾勒主页“布局”的文件:
<div id="animation">
<div class="site-container">
<div class="animation-container">
<?php include 'animation.html'; ?>
</div>
</div>
</div>_layout.scss -用于为home.php的非导入内容设置样式的文件:
#animation {
//styles <div id="animation">
}
.site-container {margin: 0 auto; max-width: 980px;}
.animation-container {
//styles <div class="animation-container">
}animation.html -包含上面导入的称为“动画”的“模块”的html。
<div class="animation-wrap">
<div class="example-selector"></div>
//more html for animation module
</div>_animation.scss -在animation.html中使用html样式
问题:,我应该如何在_animation.scss中封装选择器?
Possibilities
1.)我可以在_animation.scss中嵌套所有选择器,如下所示:
.animation-wrap {
.example-selector {
}
//all other selectors are nested here using SASS, thus they will not affect
//elements outside of the animation-wrap
}2.)我可以通过添加前缀“_animation.scss -”(以及相应的html)来命名空间中几乎所有的选择器。
.animation-wrap {}
.animation-example-selector {}3.)可以使用子选择器来减少级联,但我怀疑这是最好的,而且IE支持很差
4.)子类化?但是,我认为这与将模块移到其他地方更相关,而不是封装它以确保它不会泄漏到其他模块/布局代码中。
对这个冗长的问题很抱歉,把它写成单词是很尴尬的.任何关于最佳实践的额外建议或知识都非常感谢。
发布于 2014-03-13 19:33:58
对这个可怜的问题很抱歉。对于类似的问题,This是一个措辞更好的问题。
我决定使用SASS3.3全新的“&”灵活性来命名_animation.scss中的选择器,如下所示
.module-animation {
&-animation-wrap {
}
}这使html保持干净,封装了模块,并且不会使css中出现长前缀。
https://stackoverflow.com/questions/22363709
复制相似问题