Catch the child element of the child in css

0

I have the following html structure:

<div class="box1">
 <p>texto</p>
 <p>texto</p>
 <p><img src="imagem1.jpg"></p>
 <p>texto</p>
</div>
<div class="box2">
 <p>texto</p>
 <p>texto</p>
 <p><img src="imagem1.jpg"></p>
 <p>texto</p>
</div>

How do I apply, for example, a padding in the img tag inside box2 via css?

Thank you

    
asked by anonymous 04.08.2017 / 00:43

3 answers

1

By the title of the question, I believe the solution would be:

div > p > img {
    padding: 10px;
}

The > operator will fetch any child element directly from the related elements. That is, div > p will search for all p elements that have a parent element div and p > img will search for all img elements that have a p parent element.

See an example:

div > p > img {
  padding: 10px;
  border: 1px solid black;
}
<div class="box1">
 <p>texto</p>
 <p>texto</p>
 <p><img src="http://via.placeholder.com/350x150"></p><p>texto</p></div><divclass="box2">
 <p>texto</p>
 <p>texto</p>
 <p><img src="http://via.placeholder.com/350x150"></p><p>texto</p></div>

How Selectors Work>, +, ~ in CSS?

    
04.08.2017 / 01:01
0

use like this:

.box2 p img
{
   Código
}
    
23.08.2017 / 15:00
0
.box2 img {
   padding: 5px;
}

As you only have an image inside the box2 you can do as exemplified above (with inheritance).

    
05.04.2018 / 19:41