0

Consider the following HTML:

<div>
   <p>
     <strong>Title</strong>
   </p>
   <p>
     some resular text....
   </p>
</div>

I want to add padding to paragraph only if it has 'strong' inside it.

Is it possible using CSS only (no JS)?

Cœur
  • 32,421
  • 21
  • 173
  • 232
Illidan
  • 3,425
  • 2
  • 32
  • 39
  • 2
    In your example couldn't you just add padding to the strong tag and it would produce the same result? – Charlie Fish Jul 18 '16 at 03:53
  • 2
    Possible duplicate of [Is there a CSS parent selector?](http://stackoverflow.com/questions/1014861/is-there-a-css-parent-selector) – DAXaholic Jul 18 '16 at 03:54

2 Answers2

0

Yes, you would do this:

p > strong {
    padding:10px;
}
Luka Kerr
  • 3,750
  • 6
  • 31
  • 47
0

Yes, you can. Refer this post for learning the rules.

Demo: https://jsfiddle.net/n05jaua4/3/

HTML:

<div>
   <p>
     <strong>Title inside paragraph</strong>
   </p>
   <p>
     some resular text....
   </p>
</div>
<strong>Title</strong>

CSS:

p strong{
   padding-top: 50px;
    padding-right: 30px;
    padding-bottom: 50px;
    padding-left: 80px;
}
Community
  • 1
  • 1
PseudoAj
  • 3,634
  • 2
  • 15
  • 32