Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How do I add padding only to items after the first list item

Posted on 2011-09-10
Medium Priority
Last Modified: 2012-05-12
I have a dynamically generated ol.  I want to add top padding only to li elements which appear after the first element.  So

  <li> <-- no padding here
  <li> <-- padding here
  <li> <-- padding here

Is there a way to do this?

Question by:PurpleSlade
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 16

Expert Comment

ID: 36517441
li:not(:first-child) {...}
It doesn't work for IE6,7,8
LVL 16

Expert Comment

ID: 36518070
Use jquery:
<script src="" type="text/javascript"></script> 

Open in new window

And this script:
<script>$("ol:first").css("padding-top", "5px);</script>

Open in new window

Better give your ol an id and then use:
<script>$("#olID:first").css("padding-top", "5px);</script>

Open in new window

LVL 16

Expert Comment

ID: 36518072

<script>$("#olID:first").css("padding-top", "5px");</script>

Expert Comment

ID: 36520410
Can you show us how you dynamicaly generate the ol? Is it via Javascript? If so, just add class to the first element.

then use that class to specify the padding.

LVL 16

Accepted Solution

SSupreme earned 2000 total points
ID: 36520638
I guess the answer for this question is li:not(:first-child) {padding:10px;} , but I would do it like this:

li {padding:10px;}
li:first-child {padding:0px;}

it will work in all major browsers. *with <!DOCTYPE> declared

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question