Home  >  Article  >  Web Front-end  >  what is css selector

what is css selector

青灯夜游
青灯夜游Original
2021-03-31 16:19:502168browse

Each CSS style definition consists of two parts, in the form of "selector {style}"; the part before "{}" is the "selector". The "selector" specifies the object of the "style" in "{}", that is, which elements in the web page the "style" acts on.

what is css selector

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

To use CSS to achieve one-to-one, one-to-many or many-to-one control of elements in an HTML page, you need to use CSS selectors. Elements in HTML pages are controlled through CSS selectors.

Each css style definition consists of two parts, the form is as follows: selector{style}, the part before {} is the "selector". The "selector" specifies the object of the "style" in {}, that is, which elements in the web page the "style" acts on

Next let's look at a picture, It is a specific analysis of the above definition.

what is css selector

As shown in the figure, we can know:

The part before {} is the "selector", and the "selector" specifies the elements in {} The object of "style", that is, which elements in the web page are affected by "style"

The selector is usually the HTML element you need to change the style, such as:

,,< ;h1>Waiting

Each format declaration statement consists of a pair of "attribute name: attribute value". The attribute name and attribute value are separated by colons. Each declaration statement is preceded by a semicolon in English "; "Finish.

After introducing what a css selector is, let’s take a look at what types of css selectors there are?

What are the types of css selectors?

There are many types of css selectors. Let’s take a look at the types of css selectors

1. Tag selectors (such as: body, div, p ,ul,li).

2. Class selector (such as: class="head", class="head_logo").

3. ID selector (such as: id="name", id="name_txt").

4. Global selector (such as: *).

5. Combination selectors (such as: .head .head_logo, please note that the two selectors are separated by the space bar).

6. Inherit the selector (such as: div p, note that the two selectors are separated by the space bar).

7. Pseudo-class selector (for example: link style, pseudo-class of a element, 4 different states: link, visited, active, hover.).

8. Attribute selectors for string matching (^ $ * three types, corresponding to start, end, and inclusion respectively).

Recommended tutorial: CSS video tutorial

The above is the detailed content of what is css selector. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn