我正在使用Sass 3.4.1和BEM,所以我的scss代码如下:
.photo-of-the-day{
&--title{
font-size: 16px;
}
}
我希望每次将鼠标悬停在.photo-of-the-day
上时,都能对标题进行一些操作,这是非常常见的,通常使用css来实现:
.photo-of-the-day:hover .photo-of-the-day--title{
font-size:12px
}
事情是,使用BEM是我找到的唯一方法,但看起来有点丑
.photo-of-the-day{
&--title{
font-size: 16px;
}
&:hover{
background: red;
/* this is ugly */
.photo-of-the-day--title{
text-decoration: underline;
}
}
}
我在想是否可以继承 .photo-of-the-day
选择器,并在悬停状态下使用它,以避免再次复制整个选择器。
理想情况下应该是这样的:
.photo-of-the-day{
&--title{
font-size: 16px;
}
&:hover{
background: red;
&&--title{
text-decoration: underline;
}
}
}
在BEM中,是否有类似于返回父选择器的功能?