See this example http://jsfiddle.net/jwmCd/
HTML
<div class="round-buttons">
<a href="#">hello</a>
<a href="#">world</a>
<form method="get" action="/search" id="search">
<input name="q" type="text" size="40" placeholder="Search...">
</form>
</div>
CSS
.round-buttons a:first-child {background:red}
.round-buttons a:last-child {background:green}
.round-buttons a:last-child {background:green}
is not applying in this condition.
Dynamically there could be more links and I want to give different styling to First and last Anchor.
:last-child
will only match the last element of the parent, irrespective of its type (in your example, :last-child
will only match the <input>
). Use :last-of-type
to match the last element of a specific type in the parent, for example:
.round-buttons a:last-of-type {background:green}
Because a
is not the last child, the last child is form
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With