verrucktfuchs verrucktfuchs - 6 months ago 12
CSS Question

How do you target div last-child within another div?

I cannot work out how to target div last-child within another div? For this particular project I need it to be structured like that. Is it even possible?

JSFiddle https://jsfiddle.net/u713nw51/

HTML

<article class="outer">
<div class="inner">Text</div>
</article>

<article class="outer">
<div class="inner">Text</div>
</article>

<article class="outer">
<div class="inner">Text</div>
</article>


CSS

article { padding-bottom: 20px; }
.inner:last-child { border-bottom: 1px solid #000; }
.inner:last-child { none; }

Answer

Use this css

article:last-child .inner { border-bottom: 1px solid #000; }

Because .inner is last-child of every article so the css will reflect on all .inner. You need to target .inner in last article.

Comments