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

Posted on 2011-09-10
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
  • 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 500 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Change of column alignment in div 2 28
Little bit of help styling my heading 3 38
How to delete "dots" above Bootstrap 3 navbar 4 92
HTML question 2 27
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at Browse or search based on font properties or name to find a suitable font for…

730 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