我有问题::nth-child(n):before
在用?:nth-child(n):之前是不工作?
所以,我使用SASS。
为什么下面的代码不工作?
@for $i from 1 through 4
.block:nth-child(#{$i}):before
background: url(../../img/block-img-#{$i}.jpg)
background-size: cover
它编译成:
.content .cnt1 .block:nth-child(1):before {
background: url(../../img/block-img-1.jpg);
background-size: cover;
}
.content .cnt1 .block:nth-child(2):before {
background: url(../../img/block-img-2.jpg);
background-size: cover;
}
.content .cnt1 .block:nth-child(3):before {
background: url(../../img/block-img-3.jpg);
background-size: cover;
}
.content .cnt1 .block:nth-child(4):before {
background: url(../../img/block-img-4.jpg);
background-size: cover;
}
所有迪尔斯到的图像是真实的。但它不工作:( 我做错了吗?
你也可以举一个相应的HTML的例子吗? – Sirko
您还需要将'content:'''添加到before-rule中,我想您需要为该元素设置宽度和高度,否则背景可能会应用于0px x 0px元素。 –
为什么在每个规则中设置背景大小:封面?这似乎是完全膨胀CSS的快速方法。 – BoltClock