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 ..
- I made some li with only text (no links). the ones with no link have no icon before them(unless I put them in a span).
- and for some reason, if li has a links at the beginning, the icons became links?
- as another test for my algorithm to have a ltr text between rtl. I made some without this class. the ones without ltr class worked great in terms of position. HOWEVER, the one with this class had its icon between the text ( I assume it's due to my way of putting the icon ). 4.the last thing is the text written directly into li has no icon.
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???