weii
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    How CSS is Parsed == ###### tags: `CSS` Udemy :Advanced CSS and Sass: Flexbox, Grid, Animations and More 課程筆記 ## <font color="#3733FF">The Cascade and Specificity</font> ==CSS的第一個字C,代表的就是Cascade== 先了解瀏覽器在加載網頁時,Css代碼如何執行 解析HTML時瀏覽器會建立DOM,這時CSS也會被解析,並且有兩個解析階段 第一個是解決CSS衝突 第二個是處理最終的CSS,譬如:將百分比轉換成px值 都處理完之後就將CSS儲存在CSSOM,最後形成render tree,網站被渲染或繪製到螢幕上 ![](https://hackmd.io/_uploads/r1x6fDqVn.png) <font color="#999999">圖片來源:udemy:Advanced CSS and Sass</font> 細看第一階段在做的事情,一個網頁裡面可能有很多來源的樣式,像是 :::info Author: 開發人員定義的css,因為由「網頁開發者」制定,優先級最高 User: 使用者透過設定改變的 Browser (user agent),瀏覽器預設的,譬如超連結會是藍字+下底線 ::: 越靠近瀏覽器的來源,優先級會越高 ![CSS優先級](https://assets-lighthouse.alphacamp.co/uploads/image/file/16170/ExportedContentImage_02.png =80%x) <font color="#999999">圖片來源:Alpha camp</font> 所以要解決不同CSS規則和聲明之間的衝突,當多個規則應用於某個元素時,先查看 重要性 -> 再來查看選擇器的特殊性 -> 最後是source order的順序 從下表可以看到,查看Specificity的順序,第一個最大 有一個網站可以查詢優先順序 [polypane](https://polypane.app/css-specificity-calculator/#selector=.content%20%20.app-section%20p%20%20.highlight) 1. inline styles 2. IDs (ex: #nav) 3. classes、pseudo-classes,attribute (ex .container 、[type="radio"]、:hover) 4. elements,pseudo-elements (ex: div、::before) 最後的背景會是第二個css:綠色,最前面的數字越多,越大,如果遇到平手的狀況,就到第三個環節,寫在越下面的css就會被套用 ![](https://hackmd.io/_uploads/S1UlBDq42.png) <font color="#999999">圖片來源:udemy:Advanced CSS and Sass</font> ![](https://hackmd.io/_uploads/SJuduDqN3.png) 其他注意事項 1. 一個ID會贏過1000個class name 2. 一個class name會贏過1000個元素 3. *代表 (0, 0, 0, 0),其他的選擇器都優先於* 看到這裡就體會到,如果自己寫的css沒有work,也要檢查一下特殊性有沒有問題 範例: 這裡的horver是不會work的,它的特殊性比`nav#nav div.pull-right .button`低 ```css .button { background-color: blue; } nav#nav div.pull-right .button { background-color: green; } a { background-color: purple; } #nav a.button:hover { background-color: yellow; } ``` 所以要有horver時,要讓它的特殊性更高 ```css nav#nav div.pull-right .button:hover { background-color: pink; } ``` [codepen 連結](https://codepen.io/weeiiy/pen/dygewrY?editors=1100) ## <font color="#3733FF">Website rendering:the visual formatting model</font> 說明網頁渲染,CSS visual formatting model是一種算法,它計算每個render tree的每個元素的 box 和layout,以確定頁面的最後要呈現在頁面上的layout。 這個過程要考慮到 1. Box model 2. Box type: inline, block and inline-block 3. Positioning scheme: floats and absolute or relative positioning; 4. Stacking contexts 5. Other elements in the render tree: parents or siblings 6. Viewport size, dimensions of images, etc. 才會呈現出一個網站的樣貌 ### Box model 定義一個元素在頁面上的顯示方式和它們的大小(ex:寬、高) 有 Margin、Padding、Border、Content ![](https://hackmd.io/_uploads/By8rIdiN2.png =60%x) <font color="#999999">圖片來源:udemy:Advanced CSS and Sass</font> 現在常用的方式都是指定bor-sizing: border-box box-sizing 属性用來指定如何計算 HTML 元素的寬度和高度 當我們設定成 border-box,並指定`width: 200px` ,就代表是把盒子的border和padding都一起算進去,寬度全部加起來是200px的意思,高度也是這樣計算的 ### Box type 很多元素都有預設的type,如 | Block | Inline | | -------- | -------- | | div | span | | header | img | | section | a | | nav | em | | p | strong | | h1~h6 | label | | ol、ul、li | | | form | | | table | | - Block: 具有內容可以佔滿一整行的特性 - Inline: 則是內容只會是自己本身的大小,不能設定width 和 height屬性 - Inline-block: 改善Inline的不方便,把本來是inline屬性的元素修改成`display: inline-blick`,就可以改變box type,這樣就可以具有Block的特性,也可以設定Box model ### Positioning scheme - Normal flow: 代表`position: relative`,依據HTML內容順序呈現 - Floats: 該元素會從Normal flow被移除,我比較少用到的,如果一個元素被設置了`float: left`,該元素周圍的Text和inline elements 將會向左或向右流動,且不能調整高度,可能會導致容器的高度不足以容納其他內容或元素,可以使用 clear fixes處理 - absolute: 該元素一樣會從Normal flow被移除,但他對周圍的元素沒有影響,通常會使用top, bottom, left and right來調整位置 ### Stacking contexts 比較常見的是 `z-index`,數值越高的顯示在越前面,z-index是沒有負值的,其他會影響堆疊的還有opacity、transform 等

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully