简体   繁体   中英

Apply style with selectors css

I have this structure :

<div class="primero">
    <div>
        <div>hola</div>
        <div>hola2</div>
    </div>
</div>

How i can to apply style to the div with the content "hola2", but using css´selectors ?

thank

This should do the trick

.primero div div:last-child {
    /*your style here*/
}

http://www.w3schools.com/cssref/sel_last-child.asp

Another way:

.primero div:nth-child(2) {
    /* style here */
} 

尽管此代码有点草率,但嵌套样式将帮助您完成此操作。请确保它不会影响文档中的其他样式。

.primero > div > div:nth-child(2){your style}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM