CSS: CSS Id and Class selectors

ylbtech-CSS: CSS Id and Class selectors

 

1.Back to top
1、

CSS  Id and  Class


id and class selectors

If you want to set CSS styles on HTML elements, you need to set "id" and "class" selectors on the element.


id selector

The id selector can specify a specific style for HTML elements marked with a specific id.

The HTML element uses the id attribute to set the id selector, and the id selector in CSS is defined by "#" .

The following style rules apply to the element attribute id="para1":

example

#para1{text-align:center; color:red; }

try it"

Remark Do not start the ID attribute with a number, IDs starting with a number will not work in Mozilla/Firefox browsers.


class selector

The class selector is used to describe the style of a group of elements. The class selector is different from the id selector. The class can be used in multiple elements.

The class selector is represented by the class attribute in HTML, and in CSS, the class selector is represented by a dot ".":

In the following example, all HTML elements with the center class are centered.

example

.center{text-align:center;}

try it"

You can also specify specific HTML elements using class.

In the following example, all p elements use class="center" to center the element's text:

example

p.center{text-align:center;}

try it"

Remark The first character of a class name cannot use a number! It doesn't work in Mozilla or Firefox.

2、
2.Back to top
 
3.Back to top
 
4.Back to top
 
5.Back to top
1、
2、
 
6.Back to top
 
warn Author: ylbtech
Source: http://ylbtech.cnblogs.com/
The copyright of this article belongs to the author and the blog garden. Reprints are welcome, but this statement must be retained without the author's consent, and a link to the original text should be given in an obvious position on the article page, otherwise Reserve the right to pursue legal responsibility.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324594417&siteId=291194637