Today to Changhong interview, the interviewer asked a question, is to give a div in three places to set different background, the final div display color is which one?
At that time I was the first to answer the last one, but later said it was the first one, come back a verification, prove that they are wrong, today to summarize the scope of CSS style problem it.
First, the precedence of the HTML introduction style, the higher the number priority
# # # Style Precedence
1. Browser default settings
2. External style sheet
3. Internal style sheet (inside 4. Inline style (inside HTML elements)
---
# # # external style sheet > browser default settings
Html
```
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>cssTest</title>
<link rel= "stylesheet" type= "Text/css" href= ". /css/csstest.css ">
<body>
<div> Browser Default Style </div>
<div class= "Outstyle" > External style </div>
</body>
```
Css
```
. outstyle{
font-size:20px;
}
```
Page effect (browser default font size is 14px, external style adjusts font to 20px)
! [Enter description here] [1]
----
# # # Internal style sheet > external style sheet
Html
```
<meta charset= "UTF-8" >
<title>cssTest</title>
<style type= "Text/css" >
{font-size:10px;}
</style>
<link rel= "stylesheet" type= "Text/css" href= ". /css/csstest.css ">
<body>
<div> Internal Styles </div>
<div class= "Outstyle" > External style </div>
</body>
```
Css
```
. outstyle{
font-size:20px;
}
```
Page effect (external global style invalidated, internal global style determines font size)
Enter description here
---
# # # inline style > Internal style sheet
Html
```
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>cssTest</title>
<!--<link rel= "stylesheet" type= "Text/css" href= ". /css/csstest.css ">
<style type= "Text/css" >
*{
font-size:10px;
}
</style>
<body>
<div> Internal Styles </div>
<div style= "font-size:20px;" > Inline Styles </div>
</body>
```
Page effects (internal style invalidation, inline style determines font size)
! [Enter description here] [1]
[1]:./images/%e5%86%85%e8%81%94%e5%a4%a7%e4%ba%8e%e5%86%85%e9%83%a8_1.png "inline greater than internal"
CSS Scope issues