PDA

View Full Version : Why Specify ul li ?



Doctor_Varney
Sep 27th, 2010, 02:18 AM
Why do some people specify "ul li {---}" in their CSS? There's no comma in between ul and li, so they're not saying: "Style the ul and the li this way..." but "Style the li OF the ul this way...".

I don't put "ul li {---}", I just say: "ul {---}" then "li {---}".

Am I doing this wrong?

Dr. V

tfburges
Sep 27th, 2010, 02:37 AM
It's most likely because you can use <li> without <ul> and in most cases if you have multiple <ul> they are each formatted differently and have corresponding classes/ids... and you may want to make sure the formatting of the each <li> (specified by the CSS ul li) affects each set differently.

i.e.,


.ul1 {
background:#FF0000;
}
.ul1 li {
color:#F0F0F0;
}
.ul2 {
background:#000000;
}
.ul2 li {
color:#FFFFFF;
}

The color of all text for li under ul of class ul1 is #F0F0F0 while the color of all text for li under ul of class ul2 is #FFFFFF.

Whereas:

.ul1 {
background:#FF0000;
}
.ul2 {
background:#000000;
}
li {
color:#FFFFFF;
}
The color of all li text is #FFFFFF regardless of its parent ul class.

_Aerospace_Eng_
Sep 27th, 2010, 03:02 AM
Another reason could be if they have maybe an ordered list on the page but don't want to have that list styled the same as unordered lists.

Doctor_Varney
Sep 27th, 2010, 07:40 PM
Excellent. Thank you. Your answer's just given me some more possibilities to try with lists.

Cheers

Dr. V