Week 2 Review questions for CSS class
Please answer the first two (2) questions using the figure below:
- In the figure above, item 5 is a(n)
- embedded style sheet.
- class definition.
- id definition (id selector).
- inline style specification.
- C, id definition, identifiable by the pound
sign. It will be invoked by having an element (only one) with its id attribute
set to "rest" in the body.
- In the figure above, item 4 is a(n)
- embedded style sheet.
- class definition (class selector).
- id definition.
- inline style specification.
- B, class definition, identifiable by the period.
It will be invoked by having an element or elements with the class attribute set
to "question" in the body.
- What are some advantages of using id
over class? Please reference your response. For example, if you found
the information at an online source, indicate the URL; if you used the text, list the page; or if you
just knew, state that.
- The id approach is limited to a single use within the body,
since an id attribute is expected to be unique. The advantage only
comes when one's use shares this same behavior (though one could have a class and
just use it once). I did a search on "css
id vs class" and followed the first several results. Most discussed the uniqueness
without mentioning any advantage. I got more out of looking at the css used
by the pages than by reading what the pages had to say on the topic. There you find
that people use ids for the header, the footer, the navigation, etc., i.e.,
unique divisions on the page.
After seeing it for myself, I did run across one person (Ivan) who wrote: "Generally ids are used
for the main elements of the page, such as header, main content, sidebar, footer, etc. Classes
are used for elements that will appear several times on your page, ..."
<<http://creativebits.org/webdev/div_id_vs_div_class>>
(accessed 6/3/08) I am almost reluctant to give this reference since he then goes on to give
an example that uses the same id twice and discusses something displaying as green
that was not green on my screen.
Some people will insist on using no inline style – so that style and content are
completely separate. Any one-off effect that one might be tempted to handle using inline can
then be handled using an id. (Conversation with Steve Longo) Furthermore, one may already have
elements with ids since they are used by JavaScript.
In CSS: The Definitive Guide (edition 3, p. 37), Meyer also mentions the
advantage that the id style may apply
to more situations. For example, the class approach may not work for all XML.
Another advantage of the id is that it takes precedence over class. Thus if an element has
both an id and a class style applied to it and they conflict, the id style will win.
(Meyer and Ivan references above)
- What are some advantages of using class over id. Please
reference your response.
- The class approach can be applied to many elements within the body,
they can even be different types of elements, e.g. paragraphs (<p>) and divisions (<div>).
Furthermore, an author is also allowed to apply multiple classes to an individual element.