Current location - Quotes Website - Signature design - Difference and usage of id, class and name attributes in HTML and CSS
Difference and usage of id, class and name attributes in HTML and CSS
1, id: id is the identifier for setting the label. Used to define the unique style of an element. Name the id name with "#" at the beginning of the CSS style definition.

Usage: If the ID of a tag ID =“MyID ",use" $ ("# MyID") "to get the current tag or use" #myid{} "to define the CSS style.

2. Category: Mark and define one or more elements according to user-defined standards. A tag can have multiple classes, such as class="myclass 1 myclass2 ",and the current tag has two classes, namely myclass 1 and myclass2.

Usage: If the label has class="myclass ",you can use $ (". Myclass ") to get the label and use". Myclass{} "to define CSS styles.

3. Name: From the name, we can know that this is an attribute used to define the label name. Name can be used for data acquisition, and is often used for obtaining form data.

Usage: If the name of an input box is "My Name", then request.getparameter ("My Name") is often used to get the value of the current input box.