Solved

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

Posted on 2011-09-10
5
208 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 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
0

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
SharePoint 2013 Searchbox Branding 11 112
Menu Selected on Chrome for Windows 13 22
flex div overflows its container 4 26
CSS: How do I override in-line styling 11 24
When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
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…

808 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