Solved

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

Posted on 2011-09-10
5
188 Views
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

<ol>
  <li> <-- no padding here
  <li> <-- padding here
  <li> <-- padding here
</ol>

Is there a way to do this?

Thanks!
0
Comment
Question by:PurpleSlade
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

by:SSupreme
Comment Utility
li:not(:first-child) {...}
It doesn't work for IE6,7,8
0
 
LVL 16

Expert Comment

by:HagayMandel
Comment Utility
Use jquery:
<script src="http://code.jquery.com/jquery.min.js" 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

0
 
LVL 16

Expert Comment

by:HagayMandel
Comment Utility
Sorry:

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

Expert Comment

by:PagodNaUtak
Comment Utility
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.

.FirstOL{
padding:0px;
}
0
 
LVL 16

Accepted Solution

by:
SSupreme earned 500 total points
Comment Utility
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
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
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.
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
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 google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now