I have tried to develop my own code snippet style, and below is an example screenshot of what I have obtained so far:
This was achieved using the following CSS rules for the ordered list:
And this html code is a mix of ordered lists and paragraph styles (please ignore the span classes):
Now, visually I am quite happy with it, but code wise it sucks - it seems a little hacky and I'm sure there must be a more elegant, shorter way of achieving the same results.
Basically, I'm looking at utilising li:nth-child(odd) (and the even equivalent) but no matter what I try I can't seem to get it to work. Ideally I want to get rid of the <p class="..."> altogether, if not, at least reduced down to <p>.
So from this:
To this:
But no matter what I try, I just can't seem to get it to work. One of the biggest problems seems to be getting the line-number gutter a separate colour and getting the zebra-stripe line. Can anyone suggest fixes to the code to get what I'm after? Also, any major problems with my CSS?
Many thanks in advance.

This was achieved using the following CSS rules for the ordered list:
Code:
ol.codeSnip {
color: #555;
background-color: #edd;
font-family: Consolas, Lucida Console, Monaco, monospace;
font-size: 1em;
border: 1px solid #bbb;
border-left: 4px solid #ac6;
margin: 0em 0em 0em 2em;
padding: 0em 0em 0em 5em;
letter-spacing: 0em;
}
.codeSnip p.odd, .codeSnip p.even {
font-family: Consolas, Lucida Console, Monaco, monospace;
margin: 0em;
padding-left: 1em;
border-left: 1px solid #bbb;
letter-spacing: 0.1em;
}
.codeSnip p.odd {
background-color: #eee;
}
.codeSnip p.even {
background-color: #f5f5f5;
}
And this html code is a mix of ordered lists and paragraph styles (please ignore the span classes):
Code:
<ol class="codeSnip">
<li><p class="odd">
<span class="commentTag"><!-- this is a comment --> /* hello */</span>
</p></li>
<li><p class="even">
some text
</p></li>
<li><p class="odd">
<span class="normalTag"><html></span>
</p></li>
<li><p class="even">
<span class="propertyTag"> $port = </span>
<span class="valueTag"> 22px</span>
</p></li>
</ol>
Now, visually I am quite happy with it, but code wise it sucks - it seems a little hacky and I'm sure there must be a more elegant, shorter way of achieving the same results.
Basically, I'm looking at utilising li:nth-child(odd) (and the even equivalent) but no matter what I try I can't seem to get it to work. Ideally I want to get rid of the <p class="..."> altogether, if not, at least reduced down to <p>.
So from this:
Code:
<ol class="codeSnip">
<li><p class="odd">...</p></li>
<li><p class="even">...</p></li>
</ol>
To this:
Code:
<ol class="codeSnip">
<li>...</li>
<li>...</li>
</ol>
But no matter what I try, I just can't seem to get it to work. One of the biggest problems seems to be getting the line-number gutter a separate colour and getting the zebra-stripe line. Can anyone suggest fixes to the code to get what I'm after? Also, any major problems with my CSS?
Many thanks in advance.