Learn syntax and selector in CSS


Just a little knowledge and understanding of CSS also helps us a lot at work. To get started, in the CSS lesson below, read along with Taimienphi.vn to learn about the syntax and selector in CSS.


In the following article, Taimienphi.vn will introduce you basic syntax and selector in CSS. In addition, if you are new to CSS, readers can refer to some of the CSS lessons already on Taimienphi.vn to find out more details.

Learn syntax and selector in CSS

1. CSS syntax

CSS Style Rules include selector, property (value) and its value (value). In which the selector points to the HTML element where CSS Style is applied. CSS properties are separated by semicolons.

Find out the syntax and selector in CSS

The CSS syntax looks like this:

selector {

// CSS properties

}

For example:

The following is an example illustrating CSS syntax:

Find out the syntax and selector in CSS 2

The output will look like: Taimienphi.vn.

2. Selector in CSS

CSS Selector is used to select HTML elements (HTML element) based on element name, id, attribute, …. Selector can select one or more elements at the same time.

Find out the syntax and selector in CSS 3

3. Element selector

Element selector in CSS is used to select the HTML elements that are required to be styled. The selector declaration includes the name of the HTML element and the CSS properties applied to that element and is enclosed in {} marks.

– Element selector syntax:

The Element selector syntax looks like this:

phan tu {

// CSS properties

}

– For example:

Find out the syntax and selector in CSS 4

The output will look like: Taimienphi.vn.

id selector

The id selector is used to set the type for the given id. The id attribute is the unique identifier in the HTML document. The id selector is used with the same character #.

– Syntax id selector:

#id_name {

// CSS properties

}

– For example:

Find out the syntax and selector in CSS 5

The output will look like: Taimienphi.vn.

4. Class selector

The class selector is used to select all elements in a specific class attribute. To select elements in a specific class, we use characters (.) The same full name of a class (class name). The full class name is used to set the CSS properties for the given class.

– Class selector syntax:

.ten lop {

// CSS properties

}

– For example:

Here is an example of a Class selector:

Find out the syntax and selector in CSS 6

The output will look like: Taimienphi.vn.

The above article you read with Taimienphi.vn to learn about syntax and selector in CSS. In addition, if you have any questions or questions, you can leave your comments in the comment section below the article.

https://thuthuat.taimienphi.vn/tim-hieu-cu-phap-va-selector-rong-css-48840n.aspx
In the next CSS lessons Taimienphi.vn will introduce you further embed CSS into HTML Please.

.

Add a Comment

Your email address will not be published. Required fields are marked *