I have this CSS:
.btn-group > .btn {
margin-right: 0; // << I want this for all except last child
position: relative;
border-radius: 0;
}
Is there a way that I can make this margin-right work for all .btn except the last child?
I have this CSS:
.btn-group > .btn {
margin-right: 0; // << I want this for all except last child
position: relative;
border-radius: 0;
}
Is there a way that I can make this margin-right work for all .btn except the last child?
You can use :not()
negation CSS pseudo-class
.btn-group > .btn:not(:last-of-type) {
color: green;
}
<div class="btn-group">
<div class="btn">Button</div>
<div class="btn">Button</div>
<div class="btn">Button</div>
</div>
Try it
.btn-group > .btn:not(:last-child) {
margin-right: 0;
position: relative;
border-radius: 0;
}
use the :not() selector
.btn-group > .btn:not(#someid) {
margin-right: 0;
position: relative;
border-radius: 0;
}
Then assign id="someid"
to the innermost child
and create a new CSS
.btn#someid {
position: relative;
border-radius: 0;
}
for the last child