Skip path that CSS "walks"

0

Can I "skip the path that css runs"?

Example:

<body>
<div class="a">
     <ul class="b">
         <li class="c">
          Teste
         </li>
     </ul>
</div>
</body>

For example, I want to get the li, but as it is "too much", instead of doing this:

.a .b .c{
  blablabla;
}

Can I do this?

.a .c {
  blablabla;
}
    
asked by anonymous 31.05.2017 / 19:05

2 answers

0

Answering your question may indeed.

But by complementing, the code below

.a .c {
  blablabla;
}

will catch any element with the class c within a independent of the hierarchy, ie

<div class="a">
  <div class="c"> </div>
</div>

and

<div class="a">
  <div class="b">
    <div clas="c"></div>
  </div>
</div>

will have the same rule.

    
31.05.2017 / 20:43
0

You can make the form question, the only difference is the style will be applied to elements within a that have the class c . That is, if you have any element outside b with class c , it will also receive styles.

Note also that you can only "style" the class c , forgetting the a and b classes.

See the example below:

.a {
  background-color: green;
}

.a .c {
  background-color: blue;
}

.d {
  background-color: red;
}
<div class="a">
  <ul class="b">
    <li class="c">
      Teste
    </li>
    <li class="d">
      Teste
    </li>
  </ul>
  <p class="c"> fora de b</p>
</div>
    
31.05.2017 / 20:53