Home Web Front-end HTML Tutorial How CSS works (for tags with repeated styles, which style will the browser choose)_html/css_WEB-ITnose

How CSS works (for tags with repeated styles, which style will the browser choose)_html/css_WEB-ITnose

Jun 24, 2016 am 11:57 AM
principle Work Label style choose

For example, the tag P may have related attribute values ​​set multiple times in embedded style sheets and external style sheets (such as color: red;/color: blue). So which value does the browser use to display the style of P? ? ? This is how CSS works. (The degree of specificity is more important)

CSS has three working mechanisms: 1. Inheritance 2. Cascading 3. Specification (The cascading principle is based on inheritance and specificity)

1. Inheritance: Ancestor elements in CSS will pass one thing to descendants: the value of a CSS property. Body is the ancestor of all elements. If we specify body{color:red;}, then all elements in the document inherit this style. This is why, after we write a line of text in the Notepad program, we rename it to: xxx.html. When opened in different browsers, there will be different font effects, because each browser has its own predefined style. table, which includes the font attribute in the body, and when we open our Html with a browser, we inherit this attribute.

Of course, not all attributes can be inherited. Most of the attributes that can be inherited are related to text, such as color, font, font size, etc. Some attributes are meaningless if inherited, or will affect the layout of the page if inherited, such as those involving element positioning, margin, padding, border and other attributes.

2. Cascading: This is the C (cascading) in CSS, which is mainly based on the style source and specificity.

a) Style source: The following is the order in which the browser cascades styles from each source:

  1. Browser default style sheet
  2. User style sheets (for example, visually impaired users add a body{font-size:200%})
  3. Developer external style sheets (in the order they are introduced into the page)
  4. Developer embedded style sheet
  5. Developer inline style sheet
  6. Note: The order of 3 and 4 depends on the position of the

    is yellow

    1

    例子3:选择特指度高的(如按顺序,应该选择link的黄色,但是style中的特指度高 1-0-2 大于 1-0-1,所以选特指度高的红色),后面读取的特指度低的就不会覆盖前面特指度高的。<style>    body div #li1{color: red;}</style><link rel="stylesheet" href="demo.css"></head><body>    <div id="div1">        <ul class="ul1">            <li id="li1" class="li1">列表项1</li>

    Copy after login

    demo.css

    div #li1{
    color:yellow;}

    1

    为红色

    Copy after login

    1

    例子4:行内style有最高优先级,前面的代码不变,只在p中加了style blue,列表项立马变成蓝色虽然行内的有最高优先级,但是行内style本身就不常用(不方便移植,增加网页大小)<li id="li1" class="li1" style="color:blue;">列表项1</li>

    Copy after login

    1

    例子5 :设定的样式优于继承的样式,即使继承的样式特指度高(在li中加入em,em继承了li的特指度是102,em本身的特指度是001,但是仍然选em)<style>    body div #li1{color: red;}    em{ color:black;}</style></head><body>    <div id="div1">        <ul class="ul1">            <li id="li1" class="li1"><em>列表项1</em></li>            </ul>列表项为黑色。

    Copy after login

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Can wallpaper engine be shared among families? Can wallpaper engine be shared among families? Mar 18, 2024 pm 07:28 PM

Does Wallpaper support family sharing? Unfortunately, it cannot be supported. Still, we have solutions. For example, you can purchase with a small account or download the software and wallpapers from a large account first, and then change to the small account. Simply launching the software is perfectly fine. Can wallpaperengine be family shared? Answer: Wallpaper does not currently support the family sharing function. 1. It is understood that WallpaperEngine does not seem to be suitable for family sharing environments. 2. In order to solve this problem, it is recommended that you consider purchasing a new account; 3. Or download the required software and wallpapers in the main account first, and then switch to other accounts. 4. Just open the software with a light click and it will be fine. 5. You can view the properties on the above web page&quot;

How to set lock screen wallpaper on wallpaper engine? How to use wallpaper engine How to set lock screen wallpaper on wallpaper engine? How to use wallpaper engine Mar 13, 2024 pm 08:07 PM

WallpaperEngine is a software commonly used to set desktop wallpapers. Users can search for their favorite pictures in WallpaperEngine to generate desktop wallpapers. It also supports adding pictures from the computer to WallpaperEngine to set them as computer wallpapers. Let’s take a look at how wallpaperengine sets the lock screen wallpaper. Wallpaperengine setting lock screen wallpaper tutorial 1. First enter the software, then select installed, and click "Configure Wallpaper Options". 2. After selecting the wallpaper in separate settings, you need to click OK on the lower right. 3. Then click on the settings and preview above. 4. Next

Is there any virus when watching wallpaper engine movies? Is there any virus when watching wallpaper engine movies? Mar 18, 2024 pm 07:28 PM

Users can download various wallpapers when using WallpaperEngine, and can also use dynamic wallpapers. Many users do not know whether there are viruses when watching videos on WallpaperEngine, but video files cannot be used as viruses. Is there any virus when watching movies on wallpaperengine? Answer: No. 1. Just video files cannot be used as viruses. 2. Just make sure to download videos from trusted sources and maintain computer security measures to avoid the risk of virus infection. 3. Application wallpapers are in apk format, and apk may carry Trojan viruses. 4. WallpaperEngine itself does not have viruses, but some application wallpapers in the creative workshop may have viruses.

In which folder are the wallpapers of wallpaper engine located? In which folder are the wallpapers of wallpaper engine located? Mar 19, 2024 am 08:16 AM

When using wallpaper, users can download various wallpapers they like for use. Many users do not know which folder the wallpapers are in. The wallpapers downloaded by users are stored in the content folder. Which folder is the wallpaper in? Answer: content folder. 1. Open File Explorer. 2. Click &quot;This PC&quot; on the left. 3. Find the &quot;STEAM&quot; folder. 4. Select &quot;steamapps&quot;. 5. Click “workshop”. 6. Find the “content” folder.

Analysis of the function and principle of nohup Analysis of the function and principle of nohup Mar 25, 2024 pm 03:24 PM

Analysis of the role and principle of nohup In Unix and Unix-like operating systems, nohup is a commonly used command that is used to run commands in the background. Even if the user exits the current session or closes the terminal window, the command can still continue to be executed. In this article, we will analyze the function and principle of the nohup command in detail. 1. The role of nohup: Running commands in the background: Through the nohup command, we can let long-running commands continue to execute in the background without being affected by the user exiting the terminal session. This needs to be run

Does wallpaper engine consume a lot of power? Does wallpaper engine consume a lot of power? Mar 18, 2024 pm 08:30 PM

Users can change their computer wallpapers when using WallpaperEngine. Many users don't know that WallpaperEngine consumes a lot of power. Dynamic wallpapers consume a little more power than static wallpapers, but not a lot. Does wallpaperengine consume a lot of power? Answer: Not much. 1. Dynamic wallpapers consume a little more power than static wallpapers, but not a lot. 2. Turning on dynamic wallpaper will increase the computer's power consumption and take away a small amount of memory usage. 3. Users do not need to worry about the serious power consumption of dynamic wallpapers.

How to change font size in Microsoft Edge browser - How to change font size in Microsoft Edge browser How to change font size in Microsoft Edge browser - How to change font size in Microsoft Edge browser Mar 04, 2024 pm 05:58 PM

I guess you are not familiar with the Microsoft Edge browser, but do you know how to change the font size in the Microsoft Edge browser? The following article describes how to change the font size in the Microsoft Edge browser. Let's study it together. First, find the Microsoft Edge browser and double-click it to open it. You can find the Microsoft Edge browser in the desktop shortcut, start menu or taskbar, and double-click to open it. Secondly, open the [Settings] interface to enter this browser interface, click the [...] logo in the upper left corner; double-click [Settings] to open the settings interface. Again, find and open the [Appearance] interface and scroll down with the mouse

Which one should I choose among the five Digimon New Age games? Which one should I choose among the five Digimon New Age games? Mar 15, 2024 pm 03:58 PM

Digimon New Age is a new game that took three years to be carefully polished. This game carries everyone’s childhood memories. The plan will be adjusted and will be launched soon. Which one should you choose among the five Digimon New Ages? Let’s take a look at the five pet recommendations for Digimon New Age. Digimon New Century Five: Which one to choose from: EarthGreymon, SeaLionmon, Leomon, FairyMon, and Sunflowermon? I recommend you choose Greymon and Leomon. They are more suitable for teaming and are good pets in both the early and late stages. . Event location: 1. Open QQ, go to the game center, and find the Digimon New Century QQ exclusive reservation event; 2. Click on the event, find the entrance, and then participate in the event and start choosing your favorite partner.

See all articles