HTML and CSS Reference
In-Depth Information
Q: When I have two attributes in an
element, is the order important? For
example, should the title attribute always
come after the href?
A: The order of attributes is not important
in any element (if it were, we'd all have
headaches 24/7). So, use any ordering you
like.
Q: How would I create a tool tip for an
element that's not an <a>?
A: You can add the title attribute to any
element, so if you want a tool tip on, say, a
heading, you can add a title attribute to your
<h1> opening tag just like we did with <a>.
There are a few elements that use the title
attribute for more than just a tool tip, but the
tool tip is its most common purpose.
Q: Can I add an id attribute to any
element?
A: Yes, you can. You could link into the
middle of a paragraph by adding an id to an
<em> element, for instance. It's unlikely that
you'll often need to do that, but you can do it
if you want.
Q: Could I link to a link by adding
an id attribute to an <a> element in the
destination?
A: Yes!
Q: I noticed in the id names, you
used “chai” with all lowercase letters
and Caffeine Buzz used “Coffee” with an
uppercase “C”. Does it matter?
Q: If a web page doesn't provide a
destination and I still need to link to a
specific part of the page, how can I?
A: You can't. If there is no destination (in
other words, no element with an id), then you
can't direct the browser to go to a specific
location in a web page. You might try to
contact the page author and ask them to add
one (even better, tell them how!).
Q: Can I have a destination id like
“Jedi Mindtrick” or does an id have to be
only one word?
A: To work consistently with the most
browsers, always start your id with a letter
(A-Z or a-z) and follow it with any letter,
digit, hyphen, underscore, colon, or period.
So, while you can't use a space and have a
name like “Jedi Mindtrick”, that isn't much
of a restriction because you can always
have “Jedi-Mindtrick”, “Jedi_Mindtrick”,
“JediMindtrick”, and so on.
Q: How can I tell others what
destinations they can link to?
A: There is no established way of doing
this, and in fact, “View Source” remains the
oldest and best technique for discovering the
destinations you can link to.
Q: Do I always use just words as the
content of an <a> element?
A: No. The <a> element has always been
able to create links from words and images
(inline content), and has recently been
updated (in HTML5) so that you can create
links from block elements, like <p> and
<blockquote> too! So <a> can be used to
create links from all kinds of things.
A: You can use any combination of
upper- and lowercase characters in your
id attributes. Just make sure you are
consistent and always use the same upper-
and lowercase letters in your hrefs and
destination id (which is why it is often easier
to make these names entirely lowercase
every time). If you aren't consistent, don't
expect your links to work correctly on every
browser. The most important thing about the
id name you choose is that it must be unique
in your page.
Q: Can I put a link to a destination
from within the same document?
A: Sure. In fact, it is common to define a
destination “top” at the top of a page (say, on
the top heading of the page) and have a link
at the bottom of the page reading “Back to
top.” It is also common in long documents to
have a table of contents for the entire page.
For instance, to link to the “top” destination
heading in the same page, you would write
<a href=”#top”>Back to top</a>.
Q: Why did we need to add the “/index.
html” to the Buzz URL in order to create a
link to the destination heading? Couldn't
we have just written:
http://wickedlysmart.com/buzz#Coffee?
A: No, that won't always work because
the browser adds that trailing slash on the
end of the URL for you, which could end
up replacing the id reference. You could,
however, have written:
http://wickedlysmart.com/buzz/#Coffee,
which will produce the same results as the
link we created using “index.html”. This
will come in handy if you don't know if the
default file is named “index.html”.
Search WWH ::




Custom Search