Jump to content
MakeWebGames

What is the difference between an ID and a class?


kristi9

Recommended Posts

Re: What is the difference between an ID and a class?

POG1 one pretty much summed it all up. There's another thing I'd add to that, which is:

You can only have one id on an element. You can have any number of classes on an element.

For instance, suppose you make a class for bolding text, aligning text, and another one for making text small. You could apply those like this:

 

<style>
.bold {
font-weight: bold;
}
.left {
text-align: left;
}
.small {
font-size: 9px;
}
</style>

<p class="bold left small">...............................</p>
Link to comment
Share on other sites

Re: What is the difference between an ID and a class?

Here is a simple example of how classes could be used with ids.

<style type="text/CSS">

.box { border:1px solid #FFFF99; background: #FFFF33; }

#skinny { width:80px; }

#wide { 800px; }

</style>

<div id="skinny" class="box"> skinny? </div>

<div id="wide" class="box"> wide =) </div>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...