HTML and CSS Reference
to change the element type selector to use div instead of ul , then the styles would apply to
the <div> and not to the two <ul> elements.
Also note that the styles will not apply to the elements inside the <ul> or <div> elements.
That being said, some of the styles may be inherited by those inner elements—more on this
later in the topic.
An ID selector is declared using a hash, or pound symbol (#) preceding a string of characters.
The string of characters is defined by the developer. This selector matches any HTML ele-
ment that has an ID attribute with the same value as that of the selector, but minus the hash
Here's an example:
margin: 0 auto;
This CSS uses an ID selector to match an HTML element such as:
In this case, the fact that this is a <div> element doesn't matter—it could be any kind of
HTML element. As long as it has an ID attribute with a value of container , the styles will
on any given page with an ID of container . This makes the ID selector quite inflexible,
because the styles used in the ID selector rule set can be used only once per page.
If there happens to be more than one element on the page with the same ID, the styles will
still apply, but the HTML on such a page would be invalid from a technical standpoint, so
you'll want to avoid doing this.