CSS Scope issues

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.