By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,492 Members | 1,987 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,492 IT Pros & Developers. It's quick & easy.

User Defined ID - CSS

100+
P: 254
i have this in my text book:
An ID is just like a class, but can only be applied ONCE in a document....
what does it means?

i have tested this on my mozilla browser, and it works fine. This code contain same ID and used TWICEly.
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>ID example</title>
  4. <style type="text/css">
  5. <!--
  6. #title { color: red }
  7. h1#color { color: blue }
  8. -->
  9. </style>
  10. </head>
  11. <body>
  12. <h2 id="title">The use of the ID example</h2>
  13. <h1 id="color">Blue header but only conce</h1>
  14. <h1 id="color">BlaBlaBla</h1>
  15. </body>
  16. </html>
  17.  
So what does it means by "Can only be applied ONCE in a document?
Jan 30 '07 #1
Share this Question
Share on Google+
3 Replies


P: 24
So what does it means by "Can only be applied ONCE in a document?
Just what it says. You should only use an ID to identify a single element. If you choose to break the standards your page will not be valid HTML and may not work in all browsers.

In order to apply a style to a number of elements you need to define a class, eg.

Expand|Select|Wrap|Line Numbers
  1. <style>
  2. .features {
  3.   border : solid 1px red;
  4.   color : #444;
  5.   font-weight : bold;
  6. }
  7. </style>
  8.  
and then in your code you can apply this class to any selected element eg.

Expand|Select|Wrap|Line Numbers
  1. <h1 class="features">test</h1>
  2. <p class="features">test</p>
  3.  
Jan 30 '07 #2

100+
P: 254
that means code that i provided above might not works on all the browsers, and it is better define a CLASS instead of ID if i want to use number times of that element ?
Jan 31 '07 #3

P: 24
That's right.
Jan 31 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.