how can style be added to the first 2 list elements using CSS


Tags: css

Problem :

I have a list of the following format, how can I add style to the first 2 list elements using CSS (should work in IE8):

<ul id="list1"  style="margin-left:-20%;font-weight:bold" >
   <li class="xyz"> Element1 </li>
   <li class="xyz"> Element2 </li>
   <li class="xyz"> Element3 </li>
</ul>


Solution :

Try this way

 #list1 li:first-child
{

//styles//
}
#list1 li:first-child+li
{
  //styles//

}

    CSS Howto..

    Why the space after the table, and how to remove it?

    How to test print output of browsers with online tools?

    CSS: How to accomplish a div which is blurred at the edges?

    How to display loading.gif at the center of the screen which has a scrollbar

    How to margin div inside other div?

    How to merge css in wordpress

    how the highlighted text color and background is determined

    how do I add equal gap on each side of the text with css?

    How can I create a DIV that scrolls with the browser's scroll bar, that contains flexible content

    How is possible to get 2d transformation css vertical way

    How to make this slider control to work in both directions?

    How to hide a whole a
    if table tag is is empty or null?

    How do I make a placeholder for a 'select' box?

    CSS: how to make children fit parent's width

    How do I prevent the element of an HTML5 form from moving slightly?

    How to not send images to mobiles in a semantic manner

    How to control the area of background so it only makes a limited area has color other area don't?

    Css: how to combine table and column specification into a single selector?

    CSS - How to insure that a input will be in the middle of a specific area

    How to format the text below using css

    Cant figure out how to apply css to menus in my footer

    How to remove border in radial gradient so that it can mix well?

    How to remove mystery indents in a form?

    How to make a line before and after my h1 tag?

    how to build a triangular slider? [closed]

    How do three.js transforms and CSS3 3D-transforms correspond?

    How to set a background color defined as a CSS class (using JQuery eventually)?

    How to mark search phrase in syntax highlighted markdown code?

    How to stretch line between two cells ( tags)

    How do I add two buttons side by side that are made up of an image?