Add margin-bottom to Image Before footer
I’m trying to see if there’s a way to add a
margin-bottom to an
img element only if it’s followed by a
footer element. At the moment I’m using a special class (
image-before-footer) on my last
img element to acheive this, but was wondering if there’s a way to do it dynamically in CSS?
Any help with this is appreciated. Thanks in advance!
Since you can’t select previous sibling elements in CSS, why not just add a
margin-top to the
footer element if it follows an
img element using the adjacent sibling combinator,
You could also just select the last
img element using the
:last-of-type pseudo class.
Of course, this assumes that the last
img element will be succeeded by the