Selector syntax in CSS

-2

I have a question with the syntax of the selectors. I mean ...

If I write p.miclase{} , and declare the properties of the selector, I am declaring the properties for the html that is part of a paragraph and is affected by the class "miclase".

On the other hand, if I find the code .miclase p{} in the style sheet, I am not clear about what I should interpret and how that code is read. That is my doubt.

    
asked by Hugo Sanchez 21.03.2018 в 13:33
source

1 answer

3

That syntax refers to <p> elements that are descendants of another that has the class miclase .

p em {
  color: red;
}
<p>Hola <em>a todos</em> los que estáis aquí</p>
<p>Hola <u>a <em>todos</em> de</u> nuevo</p>

I add an additional example provided by Kiko_L to see the CSS hierarchy (ir to the original ):

.miClase {
  background-color: green;
}
.miClase p {
  background-color: red;
}
p.miClase {
  background-color: yellow;
}
<div class="miClase">
  Div con clase
  <br/>
  <p>
    Párrafo dentro de div
  </p>
  <p class="miClase">
    Párrafo dentro de div con clase
  </p>
</div>
    
answered by 21.03.2018 в 13:38