+ 2
what is the difference b/w id and class
9 ответов
+ 9
Like others have said, classes be applied to different html elements. In addition you can also use more than one class in a single html element.
One class used in multiple html elements:
<div class="centered"></div>
<p class="centered"></p>
Multiple classes used in one html element:
<div class="centered main "></div>
For id, it is unique to an element. The main advantage to this is that it can uniquely be identified and called when using javascript. Browsers can also jump to parts of an html page that have id's.
The selector for classes in css begin with a period "." For id, it is a "#". An easy way to remember is to think of an id number, so id goes with #
<div id="sidebar"></div>
.centered {
/*your style*/
}
.main {
/*your style*/
}
#sidebar {
/*your style*/
}
+ 6
A class can be applied to multiple elements, and an ID can be used just in one element.
+ 3
Classes are displayed in CSS using a dot on the start. Example: .myclass
IDs use a #: #mybox
Classes are used to set functions to any user input or action, languages like JavaScript and PhP can get data from any element using it's class. The same can happen with IDs
+ 1
id Applied To Any Specific Element And Class Can Be Applied To Any Element.
0
And alzó you can create a tag clases, i mean, style all html tags un tour documentos , example:
H1 H2 {
Color: #000000;
Text-decoration:none;
.......
}
That means, that all H1 and H2 hace the same style
0
class is the set of elements and properties,methods which are incorporated in html page.id is used as the reference to particular object or element in html page.class element is called by(#).id element is called by(.).
0
The major difference is that IDs can only be applied once per page, while classes can be used as many times on a page as needed.
0
ID can be use only one time in a page..
Class can be use many times in a page..
0
id can be applied once per page while a class can be used multiple times on a page.
# is use to represent IDs e.g #home, #about etc.
while . is used to represent a class e.g div.text { }