html5 - How to use nth-of-type without restart in css -


i have following html snippet

<body>     <p>         <span>lorem ipsum dolor sit amet, consectetur adipiscing elit.</span><br />     </p><p>         <span>morbi id vestibulum lectus. maecenas facilisis orci vitae</span><br />         <span>urna pulvinar cursus. etiam id laoreet metus. cras vitae</span><br />         <span>elit ipsum. donec sagittis nisi. sed nec nisi nibh,</span><br />         <span>fringilla fermentum quam. vestibulum lorem felis, gravida</span><br />         <span>et faucibus ac, ultrices nec lectus.</span>     </p> </body> 

my css following

span:nth-of-type(3n+1) {     color:red     } span:nth-of-type(3n+2) {     color:green     } span:nth-of-type(3n+3) {     color:blue     } 

i second span ("morbi id...) colored in green , rest of span elements follow reg-green-blue sequence. however, since span inside p element, colored in red, nth-of-type takes account order in relation parent element. how can accomplish in css?

that not possible. since both :nth-child , :nth-of-type or other variations similar these 2 related directly parents, can't skip immediate parent search next match. name "child" refers fact work on immediate siblings.

you achieve effect using jquery $("body span:eq(0), body span:eq(3)").css("color","red"); or better, if content generated through php or something, mark elements particular class using count variable, , define color inside class names in css.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -

jquery - Keeping Kendo Datepicker in min/max range -