html - select an element "inside" the :first-child pseudo selector using CSS -
html - select an element "inside" the :first-child pseudo selector using CSS -
good day all.
i have problem, construction this:
<ul> <li> <span><span> </li> <li class="selected"> <span><span> </li> <li class="selected"> <span><span> </li> <li class="selected"> <span><span> </li> <li> <span><span> </li> </ul>
i select first , lastly have selected on parent... pseudo code should this:
li.selected span { background: #ff4d6e; color: white; } li.selected:first-child span{border-radius:30px;} li.selected:last-child span{border-radius:30px;}
the problem span
within collection of .selected
have first .selected
, , span
that not possible because .selected
class element not first of parent. can workaround here using sibling selectors shown below:
/* first kid */ li.selected span{ border-radius: 30px; } /* middle children */ li.selected + li.selected span{ border-radius: 0px; } /* lastly kid */ li.selected ~ li.selected ~ li.selected span { border-radius: 30px; }
above code assuming have 3 .selected
elements. if have more , know count alter lastly kid code in above respect count. example, if have 4 .selected
elements.
li.selected ~ li.selected ~ li.selected ~ li.selected span { border-radius: 30px; }
example fiddle
html css css3 pseudo-element
Comments
Post a Comment