css - setting padding depending on number of child elements -
i have div
element may contain 1 or 2 child divs
is there way of there 1 child element
padding should 15px
otherwise 5px
it may like
<div class="container"> <div><strike>7.00</strike></div> <div>5.00</div> </div>
or
<div class="container"> <div>7.00</div> </div>
you can trick using margin in children same effect:
.container div:only-child { margin: 15px; } div { border: solid 1px red; } div div { margin: 0 5px; border-color: green; background: #ccc; } div div:first-child { margin-top: 5px } div div:last-child { margin-bottom: 5px }
<div class="container"> <div><del>7.00</del></div> <div>5.00</div> </div> <div class="container"> <div>7.00</div> </div>
ps use del
tag instead strike
deprecated
Comments
Post a Comment