July 12, 200917 yr Hi, I'm new here and am looking to move from another forum (more general computing forums) to these as my main web development ones. To start off I have a bit of a question Using the code appended I am able to create the following ordered list: The css code for the actual <ol> structure is: /* custom style for 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; overflow: auto; } .codeSnip li:nth-child(odd), .codeSnip li:nth-child(even) { font-family: Consolas, Lucida Console, Monaco, monospace; margin: 0em; padding: 0.2em 0em 0.2em 1em; border-left: 1px solid #bbb; letter-spacing: 0.1em; white-space: pre; } .codeSnip li:nth-child(odd) { background-color: #eee; } .codeSnip li:nth-child(even) { background-color: #f5f5f5; } Using the following html (please ignore the span classes): <ol class="codeSnip"> <li><span class="commentTag"><!-- this is a comment --> /* hello */</span></li> <li>some text</li> <li><span class="normalTag"><html></span></li> <li><span class="propertyTag"> $port = </span><span class="valueTag"> 22px</span></li> </ol> There are two issues I am having with this code, first is with scrollable content. At the moment when I have exceeded the width of the codeSnip area it adds a scrollbar, which is fine, but when I scroll across that area no longer retains the relevant <li> style (ie. odd or even) rather it it seems default back to the original <ol> style (ie. the darker background), as can be seen in the following picture: How can I overcome this? Secondly is a problem with IE; I have tested my code in Firefox, Safari, Opera, Chrome and IE and only in IE does it fail to render the striped lines correctly. Is there an easy IE hack to get around this as I want to leave the code as free of extra classes and tags as possible. I have got a version where I alternately classify each element as odd or even, but I'd rather not have to do that. Finally if you would like to critique my code I'd be grateful - I'm only just getting back into web design (html, css, php, mysql) after quite a hiatus, namely 5yrs of university doing a Civil Engineering degree, so I am somewhat rusty.
July 12, 200917 yr The striped problem you're having is due to the css3 psuedo :nth-child CSS3 isn't fully supported yet, and Microsoft doesn't have a good reputation for following standards anyway. three alternatives would be to use js (not everyone enables it, i.e mobile browsing) or to use a class for every other line on the li tag (a little extra coding). Or the third solution that also solves the cut off, is using a repeated background image (contains both stripes, 1px in width) and would also solve the nth problem too.
July 12, 200917 yr Author The striped problem you're having is due to the css3 psuedo :nth-child CSS3 isn't fully supported yet, and Microsoft doesn't have a good reputation for following standards anyway. Thanks, I thought it might be something along those lines, going by QuirksMode CSS Comparison it seems to be pretty much the least cross-browser compatible way I could do this - only by pure fluke is it working in anything but Firefox! three alternatives would be to use js (not everyone enables it, i.e mobile browsing) or to use a class for every other line on the li tag (a little extra coding). Or the third solution that also solves the cut off, is using a repeated background image (contains both stripes, 1px in width) and would also solve the nth problem too. I did originally apply a separate "odd" and "even" class to the <li> but I was after something more elegant, but it's obviously a little too early for that, so I will have to revert to the clunky class method. I try to stay away from images and JavaScript as much as possible - save on bandwidth, scaling issues, but I'll give it a go, see if something I like works.
Create an account or sign in to comment