Skip path that CSS "traverses"

Asked

Viewed 162 times

0

I can "skip the way css goes"?

Example:

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

There for example, I want to get the li, but as it is "a lot", instead of doing this:

.a .b .c{
  blablabla;
}

I can do that?

.a .c {
  blablabla;
}
  • 1

    Yes you can, the spacing is not a path, it’s a rule and it works like "cascade"

2 answers

0

To answer your question you can yes.

But complementing, the code below

.a .c {
  blablabla;
}

will take any element with the class c inside a independent of the hierarchy, i.e.

<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.

0

You can do in the asked way, the only difference is the style will be applied in the elements within a who possess the class c. That is, if you possess any element outside of b with class c, he will also receive the styles.

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

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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.