This may be very easy as i have a feeling i'm missing a basic point here.
Situation:
.singleOrder:first-child {
border-radius: 5px 0 0 0;
}
.singleOrder:last-child {
border-radius: 0 5px 0 0;
}
Works really well until there is only one child. In that case the second declaration will overwrite the first one and the desired effect will not be achieved.
What is the most short and elegant way to solve this?
How to select an element that is the first or last child of its parent. The :first-child pseudo class means "if this element is the first child of its parent". :last-child means "if this element is the last child of its parent". Note that only element nodes (HTML tags) count, these pseudo-classes ignore text nodes.
The :first-child: The :first-child selector is used to select those elements which are the first-child elements. For :first-child selector the <! DOCTYPE> must be declared for IE8 and earlier versions. The :first-of-type: The :first-of-type Selector is used to targeting the first child of every element of it's parent.
The :first-child selector allows you to target the first element immediately inside another element. It is defined in the CSS Selectors Level 3 spec as a “structural pseudo-class”, meaning it is used to style content based on its relationship with parent and sibling content.
Split it:
.singleOrder:first-child {
border-top-left-radius: 5px;
}
.singleOrder:last-child {
border-bottom-left-radius: 5px;
}
Or write an extra rule:
.singleOrder:first-child:last-child {
border-radius: 5px 5px 0 0;
}
Use :only-child
:
.singleOrder:only-child {
border-radius: 5px 5px 0 0;
}
Update: Yogu is right. I forgot to mention. This should come after your statements.
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