Home >Web Front-end >HTML Tutorial >Why use CSS (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
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 93f0f5c25f18dab9d176bd4f6de5d30e 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 93f0f5c25f18dab9d176bd4f6de5d30e 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 }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; }The picture below shows you the structure of the above code:
p{ color:#ff0000; }We also RGB values can be used in two ways:
p{color:rgb(255,0,0); }p{color:rgb(100%,0%,0%); }
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";}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!