![]() |
what is main difference between class and Id?
This very common question which are asked. I want the main difference with example.
|
Class can affect several elements.
ID is typically used for a single element, though you can use it on several elements. Id: Code:
#id1 {Code:
.colorcode {ID's begin with '#' Hope this helps. Here's a helpful link: http://w3schools.com/css/css_id_class.asp |
An "id" is unique and applies to one and only one element on the page. A "class" is not unique and can apply to none, every or some elements on a page.
CSS #unique {color: red;} .notunique {color: blue;} HTML <div id="unique"> ... </div> <div id="unique2" class="notunique"> <p class="notunique"> ... </p> </div> The "#" denotes an id in the CSS, but is not used in the HTML. The "." denotes a class in the CSS, but is not used in the HTML. |
Also, IDs can be used as anchor hooks to link to, e. g.:
Code:
<a href="#example">link</a> |
Quote:
Quote:
|
Quote:
And am I not correct in saying that you CAN use them for several elements? It's possible. I've done it. |
Quote:
|
code for class and I.D
The id selector is used to specify a style for a single, unique element.
The id selector uses the id attribute of the HTML element, and is defined with a "#". The style rule below will be applied to the element with id="para1": Example- #para1 { text-align:center; color:red; } Now for Class- The class selector is used to specify a style for a group of elements. Unlike the id selector, the class selector is most often used on several elements. Example- .center {text-align:center;} |
Quote:
Id's are and always have been meant to be unique. Sorry, you are incorrect. |
Quote:
Sorry, but the person before was correct. Of course you can't use one ID multiple times per page, you can use them across several pages on one website. |
Quote:
If the web page were the world and the id was "Birmingham" and you needed to go there - which Birmingham would you go to? Code:
<div id="Birmingham">England</div> |
Quote:
|
| All times are GMT +1. The time now is 06:15 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.