Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is the difference? 1

Status
Not open for further replies.
Oct 11, 2006
300
US
Hi,

What is the difference between the two of the following?
Code:
#menu {
  padding:0;
  margin:0;
  }

and

Code:
.menu {
  padding:0;
  margin:0;
  }

I do know that .menu means a CSS class which I can apply to a HTML tag (form element)

What does #menu mean and where should be used?

When I do I know when you use .menu or #menu?

Thanks.
 
The first: #menu : the hash mark means that this is an element ID reference. Used like this

Code:
<div id="menu">...</div>

ID's are unique -so there can be only one tag with the same ID in the same html document.

The second: .menu :the dot means that this in an element class identifier. Used like this:

Code:
<div class="menu">...</div>

classes are ... classes. Hence there can be as many as you see fit tag with the same class in the same html document.
 
The pound sign (#) means that the CSS applies to all elements with the ID menu (id="menu").

Using the period in front of a CSS pseudoclass means that anything on the page will be rendered according to that CSS with class="menu" in the element open tag.

Lee
 
So bacially you should use the # (hash) for things that arear only once per page and the . (dot) for things that apear more than once per page.

Does this make sense 2u?
 
You use the # if you want to apply the style to a specific ID, and the . if you're using the style as a pseudoclass without regard to the ID.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top