Solved

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

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Unordered lists (HTML ul tags) are very handy to create menus of all types, shapes and sizes.  All it takes is a little knowledge of CSS and the possibilities are endless. First off, you should know the general format for menus created using the …
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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…

777 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