| | |
List items: pointing to a specific li
Please support our HTML and CSS advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Hi there
I've been trying to find out how to point to a specific li in a list but no matter what search term I use in google I cant find what I'm looking for.
Basically I want to point to a specific li using css. So for instance I have 5 list items and I want to style list item 3. How would I go about pointing to that specific li?
I've been trying to find out how to point to a specific li in a list but no matter what search term I use in google I cant find what I'm looking for.
Basically I want to point to a specific li using css. So for instance I have 5 list items and I want to style list item 3. How would I go about pointing to that specific li?
This user has a spatula. We don't know why, but we are afraid.
Venom,
Give the li in question a class name that is different from the other lis in the list, than address it by that class name in css.
Airshow
Give the li in question a class name that is different from the other lis in the list, than address it by that class name in css.
HTML and CSS Syntax (Toggle Plain Text)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Airshow :: Untitled</title> <style type="text/css"> li.normal { color:green; }/*style as required*/ li.special { color:red; font-weight:bold; }/* something special for one or more particular items */ </style> </head> <body> <ul> <li class="normal">List item 1</li> <li class="normal">List item 2</li> <li class="special">List item 3</li> <li class="normal">List item 4</li> <li class="normal">List item 5</li> </ul> </body> </html>
50% of the solution lies in accurately describing the problem!
•
•
•
•
Venom,
Give the li in question a class name that is different from the other lis in the list, than address it by that class name in css.
AirshowHTML and CSS Syntax (Toggle Plain Text)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Airshow :: Untitled</title> <style type="text/css"> li.normal { color:green; }/*style as required*/ li.special { color:red; font-weight:bold; }/* something special for one or more particular items */ </style> </head> <body> <ul> <li class="normal">List item 1</li> <li class="normal">List item 2</li> <li class="special">List item 3</li> <li class="normal">List item 4</li> <li class="normal">List item 5</li> </ul> </body> </html>
I know there's a way in CSS to point to a specific li. Take the following code for instance:
html Syntax (Toggle Plain Text)
<ul class='parent'> <li>Copy goes here. <ul> <li>item 1</li> <li>item 2</li> </ul> </li> </ul>
css Syntax (Toggle Plain Text)
.parent li ul li { /* css properties goes her */ }
So using the example above, I just want to point to item 2. I hope that makes sense.
This user has a spatula. We don't know why, but we are afraid.
Maybe you want to work with pseudo-classes? But I think they have a sketchy implementation in IE6-7 or lower. Anyway, the only pseudo-class I've seen that might apply is the first-child pseudoclass. And there's no second-child pseudoclass. =(
maybe you can use javascript and detect the 2nd element of the array containing the list items... but that's too complicated.
How are you implementing the dynamic generation? Perhaps there's a way to mark item2 before the html code is generated.
maybe you can use javascript and detect the 2nd element of the array containing the list items... but that's too complicated.
How are you implementing the dynamic generation? Perhaps there's a way to mark item2 before the html code is generated.
If you know ASP, you can save other daniweb members from idiots like me by helping out in this forum.
Visit this thread if your username starts with one of the following letters: B D F H J L N P R T X Y Z.
Visit this thread if your username starts with one of the following letters: B D F H J L N P R T X Y Z.
Venom,
Yes that makes sense. Trouble is you can't address a specific li in a list unless it is the first-child (pseudo-class).
So you come back to having to give your target li a class (or an id) such that it can be addressed in css.
You say the list is dynamic. You need to inject a class/id wherever the list is built. If it is built in javascript you could also style it directly with emement.style.whatevere.... but this is cumbersome compared with giving it a .styleName .
Airshow
edit: more or less exactly what kanaku says above.
Yes that makes sense. Trouble is you can't address a specific li in a list unless it is the first-child (pseudo-class).
So you come back to having to give your target li a class (or an id) such that it can be addressed in css.
You say the list is dynamic. You need to inject a class/id wherever the list is built. If it is built in javascript you could also style it directly with emement.style.whatevere.... but this is cumbersome compared with giving it a .styleName .
Airshow
edit: more or less exactly what kanaku says above.
Last edited by Airshow; Jul 14th, 2009 at 8:23 am.
50% of the solution lies in accurately describing the problem!
![]() |
Similar Threads
- adding list items (Python)
- Should items table be divided into categories?? (Database Design)
- Items with some, but not all, fields in common (Database Design)
- Go to specific control (VB.NET)
- Style for just numbers in ol lists (HTML and CSS)
- Sorting a List of Items (Java)
- Listing items only from an specific range (ColdFusion)
- DropDownList items (ASP.NET)
Other Threads in the HTML and CSS Forum
- Previous Thread: Css border showing double
- Next Thread: Within a <td>, how do I call a Javascript function on ANY event?
| Thread Tools | Search this Thread |
appointments asp background backgroundcolor beta browser bug calendar cart cgi code codeinjection corporateidentity css design development displayimageinsteadofflash dreamweaver emailmarketing epilepsy explorer firefox flash form format google griefers hackers hitcounter hover html ide ie7 ie8 iframe image images internet internetexplorer intranet iphone javascript jpeg layout macbook maps marketshare microsoft mozilla multimedia navigationbars news offshoreoutsourcingcompany opacity opera optimization perl pnginie6 positioning problem scroll seo shopping studio swf swf. textcolor timecolor titletags url urlseparatedwords visual visualization web webdevelopment webform website windows7 xml xsl





