Reputation: 509
okay I have an rtl website. there is a ul with many li. the first words in each li are ltr a links. What I wanted to do was simple. I want to have a frontAwesome icon before each li so I did the code normally
html
<ul class="vocab">
<li>CPU(central processing unit).: وحدة المعالجة المركزية</li>
<li><a href="" class="ltr">CPU(central processing unit).</a>: وحدة المعالجة المركزية</li>
<li><a href="">CPU(central processing unit)</a>: وحدة المعالجة المركزية</li>
<li><a href="">CPU(central processing unit)</a>: وحدة المعالجة المركزية</li>
<li><a href="">CPU(central processing unit)</a>: وحدة المعالجة المركزية</li>
<li><span class="ltr">left ...</span></li>
</ul>
This is the scss
body {
margin: 0;
padding: 0;
background-color: #ffffff;
direction: rtl;
}
.ltr {
direction: ltr;
display: inline-block;
}
.vocab{
list-style: none;
width: 70%;
border-right: 3px solid rgba(77, 181, 56, 1);
background-color: rgba(77, 181, 56, .1);
padding: $p;
margin: 0 auto;
padding-right: 2 * $h1;
li {
padding-right: $h1;
:before{
content: "\f137";
font-family: FontAwesome;
display: inline-block;
margin-right: -$h1;
width: $h1;
}
}
}
four problems happened ..
here is the output: output without solution solved
my solution is a bit weird. and it is what I need an explanation of HOW DID IT WORK?
what I did .. I made ONE change in my scss.. I made :before into li:before and didn't nest it
.vocab{
list-style: none;
width: 70%;
border-right: 3px solid rgba(77, 181, 56, 1);
background-color: rgba(77, 181, 56, .1);
padding: $p;
margin: 0 auto;
padding-right: 2 * $h1;
li {
padding-right: $h1;
}
li:before{
content: "\f137";
font-family: FontAwesome;
display: inline-block;
margin-right: -$h1;
width: $h1;
}
}
to sum up .. when I made :before nested inside li which is nested in .vocab .. it didn't work and actually gave up some weird output BUT, when I made li:before nested inside .vocab (not :before nested with li) it worked WHY? isn't it basically the same thing???
Upvotes: 1
Views: 58
Reputation: 55
As pointed out by Qunetin, the correct syntax is
.li {
&::before {
//stuff
}
}
But also remember that the correct syntax for pseudoelements is the double colon (::before). The single colon (:hover) is used for pseudoclasses
Upvotes: -1
Reputation: 943981
The SCSS:
li {
:before {
foo: bar
}
}
represents the CSS:
li :before { foo: bar }
The space is a descendant combinator.
You are trying to get:
li:before { foo: bar }
i.e. "Before the li" and not "Before each of the li's descendents".
You can use an ampersand to supress the descendent combinator:
li {
&:before {
foo: bar
}
}
Upvotes: 4