How to select first 2 elements using css

For first 2 li elements inside ul p try:

.one ul li:nth-child(-n+3){
    // your style
}

See on jsfiddle

And as other mates mentioned: you have invalid markup.

If you removed p element, try:

.one ul li:nth-child(-n+2){
    // your style
}

See on jsfiddle

Update: My suggestion is to use another ul instead of p: So you have valid markup and same result:

HTML

<div class="one">
    <ul>
        <li>0</li>
        <li>
            <ul>
                <li>One</li>
                <li>Two</li>
                <li>3</li>
            </ul>
        <li>
        <li>Four</li>
        <li>Five</li>
    </ul>
</div>

CSS:

.one ul {
    padding: 0;
    list-style-type: none;
}
.one ul ul li:nth-child(-n+2){
    // your style
}

Updated jsfiddle

Note: As your last comment, If you have only 2 special li element, Why not define a class name simply… <li class="bold"> Do it simple

ul li.bold {
    // your style
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)