Why use CSS (Cascading Style Sheets)

零下一度
Release: 2017-06-24 11:41:36
Original
2231 people have browsed it

Today we are mainly talking about css style sheet! Using it in combination with HTML can make the HTML page become very colorful!

Let me briefly introduce why to use CSS (Cascading Style Sheets) cascading style sheets!


 1. Because CSS style sheets can define how HTML elements are displayed

 2. All major browsers support CSS style sheets

 3. Style sheets are extremely Greatly improve work efficiency

 4. Moreover, multiple style sheets can be cascaded into one

If the same HTML element is used by more than one When defining a style, which style will be used?

Generally speaking, all styles will be cascaded in a new virtual style sheet according to the following rules, among which the 4th one has the highest Priority.

## 1.Browser default settings

 2.External style sheet

3. Internal style sheet (located inside the tag)

4. Inline style (inside the HTML element)

Therefore, an inline style has the highest priority, which means it will take precedence over the following style declarations: style declarations in the tag, style declarations in external style sheets Statement, or browser style statement (default value)!

The following syntax is introduced below:

CSS rules mainly have two parts Composition: selector, and one or more declarations.

1 div{2     width:100px;3     height:100px;4 }
Copy after login
The selector is usually the HTML element that you need to change the style.

Each declaration consists of an attribute and Composed of a value!

The property is the style attribute you want to set. Each attribute has a value. The attribute and value are separated by a colon.

The following line of code The function is to define the text color in the H1 element as red and set the font size to 14 pixels.

In this example, .h1 is the selector, color and font-size are attributes.red and 14px is the value.

h1{
    color:red;
    font-size:14px;
}
Copy after login
The picture below shows you the structure of the above code:

Different writing methods and units of values:
In addition to the English word red, we can also use hexadecimal color values#ff0000;

p{
    color:#ff0000;
}
Copy after login
We also RGB values ​​can be used in two ways:

p{color:rgb(255,0,0);
}p{color:rgb(100%,0%,0%);
}
Copy after login

Remember to write quotes:

Tip: If If the value is a number of words, add quotation marks to the value;

p{

font-family: "sans serif";

}


I’ll be here today! See you tomorrow!!!

The above is the detailed content of Why use CSS (Cascading Style Sheets). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template