在SASS中,如何引用父级?
如果层次结构如下所示: .all .d1 .d2 全部的 .d1 .d2 我想选择“.all”到“.d2”。怎么样?例如: .all .d1 .d2 &:hover & .all ... 全部的 .d1 .d2 &:悬停 &.全部 ...在SASS中,如何引用父级?,sass,Sass,如果层次结构如下所示: .all .d1 .d2 全部的 .d1 .d2 我想选择“.all”到“.d2”。怎么样?例如: .all .d1 .d2 &:hover & .all ... 全部的 .d1 .d2 &:悬停 &.全部 ... 要编译的“&.all”行。all 您希望输出什么?在给定的示例中,您将得到如下选择器: .all .d1 .d2.all:hover …如果我知道SASS(我使用更少
要编译的“&.all”行。all 您希望输出什么?在给定的示例中,您将得到如下选择器:
.all .d1 .d2.all:hover
…如果我知道SASS(我使用更少)
这就是你想要的,还是你最终想要的?如果你只是想对
做点什么,那么你可以这样做,例如:
.all
color: red
如果要更改
中的所有内容,可以执行以下操作:
.all *
color: red
.all > *
color: red
最后,如果只想更改
的直接子级,可以执行以下操作:
.all *
color: red
.all > *
color: red
您只需在下定义所需样式。所有:
.all
background: #000 center center no-repeat
margin: 0 auto
.dl
background: #fff center center no-repeat
margin: 15px
&:hover
margin: 0
text-decoration: none
这将输出为
.all {
background: #000 center center no-repeat;
margin: 0 auto;
}
.all .d1 {
background: #fff center center no-repeat;
margin: 15px;
}
.all .d1:hover {
margin: 0;
text-decoration: none;
}
编辑
一开始我不明白你的问题。答案是,通过CSS这是不可行的。您需要使用jQuery来完成以下任务:
.all .d1 .d2.all:hover
像这样:
SASS
.all
position: relative
display: block
height: 100px
width: 100px
z-index: 1
.dl
position: absolute
top: 50%
left: 50%
display: block
height: 50px
width: 50px
margin: -25px 0 0 -25px
z-index: 2
background: white
.all1
background: green
.all2
background: red
Javascript
$(".dl").hover(function () {
$(".all").removeClass(".all1")
$(".all").addClass("all2");
});
你做不到,想这样做也没有什么意义。没有用于编译的等效CSS。是否要选择
.all
中的每个元素,或选择.all:悬停
?你能提供你期望的CSS吗?我想更改div“.all”。我想更改div“.all”。没有任何选项。我想更改div“.all”that is father“.d1”和此“.d2”,通过事件:hover“on the div”.d2”。此代码将更改“.d1”,但没有。所有“in event”:hover。您想说。all:hoverNo,“.d2:hover”modify.all”.我相信就这些了:悬停d2:hover@RafaelLaurindo你需要编辑你的问题,以便更清楚地知道你想要什么。此外,我不是100%你想要的是可以通过CSS,jQuery可能会得到你更多的结果。最后尝试我的编辑,看看是否有帮助。