Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-26-2012, 03:58 PM   PM User | #1
johndove
Regular Coder

 
Join Date: Jul 2005
Posts: 103
Thanks: 31
Thanked 0 Times in 0 Posts
johndove is an unknown quantity at this point
Nth child selector to alternate colors

Please see url http://badidea.backstageweb.net/2012...-i/#comment-13 (responses)

I am trying to use the nth selector to alternate colors (#fff and #F4FCEB) of every other response but I'm not having any success. Can anyone tell me what I'm doing wrong?

Code:
ul.children {
    background-color: #F4FCEB;
    box-shadow: 0 0 8px #888888 inset;
    list-style: none outside none;
    margin: 10px;
    padding: 12px;
}

ul.children:nth-child(2n) {
    background-color: #FFFFFF;
}
Thanks,

John
johndove is offline   Reply With Quote
Old 11-26-2012, 05:47 PM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,615
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
It’s not the lists you should style but rather the list items because the lists aren’t repeating themselves, they will never be an alternate. Also, there are simple keywords for these cases:
Code:
.children li:nth-child(even) {…}
__________________
Don’t click this link!
VIPStephan is online now   Reply With Quote
Old 11-26-2012, 06:10 PM   PM User | #3
johndove
Regular Coder

 
Join Date: Jul 2005
Posts: 103
Thanks: 31
Thanked 0 Times in 0 Posts
johndove is an unknown quantity at this point
Stephan, still not alternating ?

Code:
ul.children{
	background-color:#f4fceb;
	margin:10px;
	padding:12px;
	list-style:none;
	-moz-box-shadow: inset 0 0 8px #888;
	-webkit-box-shadow: inset 0 0 8px#888;
	box-shadow: inset 0 0 8px #888;
	}
	
ul.children li:nth-child(even){	
	background-color:#fff;
	}
johndove is offline   Reply With Quote
Old 11-26-2012, 06:27 PM   PM User | #4
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,615
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Ah, OK, I think I get it: You want each child of a list to be of the alternate color of the parent? For that the :nth-child pseudo-class doesn’t work. I don’t even know if there is any general selector for this but I don’t think so. You need to do it manually, like:
Code:
.children {[color 1]}
.children ul {[color 2]}
.children ul ul {[color 1]}
.children ul ul ul {[color 2]}
…
__________________
Don’t click this link!
VIPStephan is online now   Reply With Quote
Old 11-26-2012, 07:11 PM   PM User | #5
johndove
Regular Coder

 
Join Date: Jul 2005
Posts: 103
Thanks: 31
Thanked 0 Times in 0 Posts
johndove is an unknown quantity at this point
Stephan, thanks!

Almost there, only trouble now is I have a list-style-type:circle on my original comment (10:27 a.m.) that I want off. Can't find the style. - ?

Code:
.children ul{
	background-color:#fff;
	margin:10px;
	padding:12px;
	list-style:none;
	/*border:2px solid #C1E0FF;*/
	-moz-box-shadow: inset 0 0 8px #888;
	-webkit-box-shadow: inset 0 0 8px#888;
	box-shadow: inset 0 0 8px #888;
	list-style-type:none;
	}
	
.children ul ul {background-color:#f4fceb;}
.children ul ul ul {background-color:#fff;}
.children ul ul ul ul {background-color:#f4fceb;}
.children ul ul ul ul ul {background-color:#fff;}
.children ul ul ul ul ul ul {background-color:#f4fceb;}
.children ul ul ul ul ul ul ul {background-color:#fff;}

li.comment-body {list-style-type:none;} (that's not it).
johndove is offline   Reply With Quote
Old 11-26-2012, 07:56 PM   PM User | #6
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,615
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Well, .children li {list-style: none;} is working for me.
__________________
Don’t click this link!
VIPStephan is online now   Reply With Quote
Users who have thanked VIPStephan for this post:
johndove (11-26-2012)
Old 11-26-2012, 08:00 PM   PM User | #7
johndove
Regular Coder

 
Join Date: Jul 2005
Posts: 103
Thanks: 31
Thanked 0 Times in 0 Posts
johndove is an unknown quantity at this point
Thank you!
johndove is offline   Reply With Quote
Reply

Bookmarks

Tags
nth child

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:14 AM.


Advertisement
Log in to turn off these ads.