"Maury Merkin" <merkin (AT) his (DOT) com> wrote:
Quote:
Question 1:
Everyone here seems settled that the <div> tag is the place for an id
attribute and <span> tags are for class attributes. |
The id attribute is a unique identifier, used to name a single element
on a page. (This isn't merely a custom or common practice, it's a rule
of HTML. Using the same id value twice on one page results in an
invalid page.) Applying a style to the element that has a particular
id is only one of the uses of the id attribute. Other uses include
setting destinations for internal document links and DOM manipulation
by script.
The class attribute is to indicate that any number of elements are
intended to share some set of characteristics, typically a set of
styles. For example, you might have classes for names of species
(recalling a discussion held here several months ago), links to
entries in your web site's glossary (as distinct from links to any
other page), footnotes, lines of poetry, and so on.
If you use DIVs to divide your page up into its principal components,
then, yes, each DIV will probably have a distinctive function that
would be best reflected in a unique ID: "banner", "leftnav", "topnav",
"footer", "sidebar", "maincontent". These are things of which the page
has one each. So it makes sense that *these* DIVs would have id
attributes, which would be used to apply styles specific to one or
another of them. But if, say, you have a lot of photographs on your
page, each with information related to it in a particular format, then
you might want to wrap a DIV around each photo with its info, and
format all these DIVs the same way. That would call for a class rather
than an ID.
There isn't generally any reason why a non-block element on a page
would warrant having a style assigned to it based on a unique ID, even
if it has one. So for spans, styles will most likely be associated
with them based on classes (like "species", "glossarylink", "poetry",
"footnote", and so forth)..
Quote:
Why? It seems to me
that they are interchangeable. (Something about the aesthetics of the
whole thing wants to do away with <div> tags altogether and simply use
span>. Is there some trap in doing this that I haven't found yet?) |
DIVs are blocks and SPANs are inline. Yes, you can change that with
CSS, but speaking in terms of document structure, a DIV is, a full
division of the page, if you think of a page being broken up into
blocks. A span is not necessarily an integral component of anything.
--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ôter le premier point de mon adresse de courriel.