CSS Question

T

Tobias G

When yo declare styles you place a . (period) before the style name.
I sometimes see the # (pound sign) used instead. What is the
difference?

is . used with class? and # used with ID?


Thanks,
Tobias
 
T

Toby A Inkster

Tobias said:
is . used with class? and # used with ID?

Correct.

It is also possible to use notation like:

div.blah - means any <div> with class="blah" (or class="foo blah bar", as
an element can have more than one class!)

div#blah - means any <div> with id="blah".

div[class=blah] - the same as div.blah, but this notation isn't understood
by IE.

div[id=blah] - the same as div#blah, but this notation isn't understood
by IE.

div[foo=bar] - generalisation of the two above. Can be very useful, for
example a[rel=next] will apply a style to any links to the next page.

and many, many more!
 
A

Andy Holmes

Toby said:
Tobias G wrote:




Correct.

It is also possible to use notation like:

div.blah - means any <div> with class="blah" (or class="foo blah bar", as
an element can have more than one class!)

div#blah - means any <div> with id="blah".

Keeping in mind, of course, that you can only use each id *one* time, so
if your style is applying to more than one element, use a class (.foo)
rather than an id (#bar).

eg.



<ul id="navigation">
<li>Home</li>
<li>News - <em class="red">updated!</em></li>
<li>Movie Reviews - <em class="red">updated!</em></li>
<li>About</li>
</ul>
 
M

Matthias Gutfeldt

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,079
Messages
2,570,574
Members
47,206
Latest member
Zenden

Latest Threads

Top