Reputation: 3896
I am often stuck on this problem where I have a parent element with an "ID" and a group of child elements which don't have any "ID" or "CLASS" to be target specifically.
Sometimes, I really don't have an option to specify an "ID" or "Class" to an element so I can just easily target the element. I also don't have a privilege to use javascript to override. So I am really just stuck using CSS to style it.
Are there approaches in CSS where I can target a specific element?
See my Example Problem:
I just want to isolate "Item 4" and highlight it. This is the best I can do but It's also wrong because It's targeting "Item 5",should ONLY highlight "Item 4".
Thanks.
Upvotes: 0
Views: 2400
Reputation: 2094
You could do it like this:
#list_item li:nth-child(4)
And similarly also for the table and div. Look here for browser suppoport.
Upvotes: 1
Reputation: 14575
The n'th child selector is what you are looking for. http://css-tricks.com/how-nth-child-works/
Upvotes: 2