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
  • 37,241
  • 25
  • 195
  • 267
Illidan
  • 4,047
  • 3
  • 39
  • 49
  • 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
  • 4,161
  • 7
  • 39
  • 50
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
  • 5,234
  • 2
  • 17
  • 37