?
Solved

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

Posted on 2011-09-10
5
Medium Priority
?
233 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
ID: 36517441
li:not(:first-child) {...}
It doesn't work for IE6,7,8
0
 
LVL 16

Expert Comment

by:HagayMandel
ID: 36518070
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
ID: 36518072
Sorry:

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

Expert Comment

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

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

Accepted Solution

by:
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
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…
Suggested Courses
Course of the Month3 days, 19 hours left to enroll

600 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