So if I have a CSS class named “class-name”, what does the following mean?
.class-name {
margin: 0;
}
And why, if I had the following HTML
<div id="some-id">
<ul>
<li class="class-name">
...
would the selector
#some-id .class-name ul li
not exist?
The first one means what you probably think it means: Any HTML element with the class
class-namewill have a margin of 0 width (for each side, ie. top, bottom, left and right).The second question is a bit more subtle. This selector
Applies only to an
lithat is found under aul, found under an element with a class ofclass-name, found under an element with idsome-id.You would have to use a selector like this to apply to the HTML you have above:
Note that there is no space between
liand.class-namein that selector. Specifyingli.class-namemeans “anliwith the class nameclass-name“, whereasli .class-name(with a space) would mean “element with classclass-namefound below anli“.