Inline CSS style, written directly in existing HTML tags
Where can CSS styles be written? From the form of CSS-style code insertion, the basic can be divided into the following 3 kinds: inline, embedded and external three kinds.
内联式CSS style sheet is to write CSS code directly in the existing HTML tags, such as the following code:
<p style= "Color:red" > here the text is red. </p>
Note that it is wrong to write in the start tag of the element:
<p> here the text is red. </p style= "color:red" >
and CSS style code to write in style= "" double quotes, if there are multiple CSS style code settings can be written together, separated by semicolons. The following code:
<p style= "color:red ; font-size:12px" > here the text is red. </p>
Embedded CSS style, written in the current file
Now there is a task, the right editor in the "Cool Internet", "service timely intimate", "fun and easy to learn" The three short word text size modified to 18px. It would be a headache to set up the inline CSS style that we learned in the last lesson (adding sytle= "font-size:18px" to each <span> tag), this section explains a new way of embedding CSS styles to accomplish this task.
The embedded CSS style is the ability to write CSS style code between <style type= "text/css" ></style> tags. The following code is implemented to set the text in three <span> tags to red:
<style type= "Text/css" >span{color:red;} </style>
Embedded CSS styles must be written between <style></style>, and in general the embedded CSS style is written between
External CSS style, written in a separate file
An external CSS style (also known as an inline) is to write the CSS code in a separate external file, with the CSS style file " .css " as the extension, within
<link href="base.css" rel="stylesheet" type="text/css" />
Attention:
1. CSS style file names are named with meaningful English letters, such as MAIN.CSS.
2, rel= "stylesheet" type= "text/css" is fixed notation cannot be modified.
3, <link> label location is generally written in the
Three ways to prioritize
Some of the small partners asked, if there is a situation: for the same element we have three ways to set CSS style, then which method really effective? That's what happens in the editor on the right.
1. Use 内联式 CSS to set "super cool Internet" text for 粉色 .
2. Then use 嵌入式 CSS to set the text to 红色 .
3, and finally use 外部式 the settings text 蓝色 (style.css file Settings).
But eventually you can observe that the text of the short word "super cool Internet" is set in order 粉色 . Because these three styles are prioritized, remember their priorities:内联式 > 嵌入式 > 外部式
But embedded > external has a premise: the placement of the embedded CSS style must be behind the exterior. As is the case with the right code editor, <link href= "Style.css" ...> code in front of <style type= "Text/css" >...</style> Code (also written in the actual development). Interested partners can try, change them in order, and see if their priority changes.
In fact, in summary, that is --就近原则(离被设置元素越近优先级别越高) .
CSS style Basics