Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

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

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
PurpleSlade
Asked:
PurpleSlade
  • 2
  • 2
1 Solution
 
SSupremeCommented:
li:not(:first-child) {...}
It doesn't work for IE6,7,8
0
 
HagayMandelCommented:
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
 
HagayMandelCommented:
Sorry:

<script>$("#olID:first").css("padding-top", "5px");</script>
0
 
PagodNaUtakCommented:
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
 
SSupremeCommented:
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now