I'd like have a margin on an element, on the right if the element is the first element of the parent <div>
, or on the left if the element is the last element of the parent <div>
.
The thing is, there is no other element in the <div>
, only plain text.
Here's where I am:
HTML:
<div class="parent">
<i>→</i>Action
</div>
<div class="parent">
Action<i>←</i>
</div>
CSS:
.parent i:first-child {
margin-right: 5px;
}
.parent i:last-child {
margin-left: 5px;
}
With the first selector I'm trying to target the first <div>
, and with the last selector I'm trying to target the last <div>
.
But actually since <i>
is the only child element, both rules apply to this element.
See fiddle.
Is there a way I can select the <i>
that is at the beginning or the end of the parent, without modifying the markup? (Adding a <span>
to wrap the text is not the solution I'm looking for...)