Home > Web Front-end > Front-end Q&A > How to use css

How to use css

WBOY
Release: 2023-05-21 11:25:38
Original
613 people have browsed it

CSS (Cascading Style Sheets) is a language used to define web page styles. It is used together with HTML to build web pages. CSS controls the appearance and position of HTML elements to beautify web pages and improve user experience.

In this article, we will introduce the basics of CSS and how to use CSS to change the style of HTML elements.

CSS Basics

CSS consists of selectors and declarations. Selectors are used to select HTML elements to which styles should be applied, while declarations specify the styles to be applied to the selected elements.

Selectors

The following are some common selectors:

Declarations

Declarations are part of CSS rules, and each declaration consists of attributes and values. The attribute specifies the style to be applied, and the value determines the specific value of the attribute. For example:

p {
  color: red;
}
Copy after login

In this rule, "color" is the attribute and "red" is the value. This will select all

elements in the document and set their color to red.

How to apply CSS

CSS can be applied to HTML documents in three ways: internal style sheets, external style sheets, and inline styles. We will look at each of these three methods separately.

Internal style sheet

Internal style sheet means that CSS rules are included in the