4j_626
    • 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

      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.
      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
    • 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 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

    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.
    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
    # CSS3 flex ## 寫在flex前 * CSS排版演化史:table > float(CSS2) > flex(CSS3,主流) > grid(最新,返祖) * 特性論:flex預設不斷行;float預設超過寬度自動斷行。 * 功能論:flex適用於小版面,grid適用於大版面;flex難達成文繞圖,float易達成文繞圖。 ## flex系統撰寫手順舉例 ```css=! 父層 { /* flex預設橫向排列且等高 */ display: flex; /* 決定用flex模式 */ flex-direction: row; /* 設置主軸方向及斷行與否 */ flex-wrap: wrap; align-content: center; /* 雙向置中 */ justify-content: center; } 子層 { flex-basis: auto; flex-grow: 1; /* 決定是否參與空間分配及收縮 */ flex-shrink:1; } ``` ## 父層設定 ### display: flex; > 設置於父層 * 設置於父層,該元素即是一個flex box;並將子元素定義為flex item,預設寬度是最小寬度。須特別注意影響層級只會到子層,不會繼承到孫層。 * 子元素伸縮項目的預設高度是和父層等高。 * flex box的區塊配置,是以剩餘空間的概念在設置。 * flex box有主軸、側軸之分;物件排列主要是依據主軸(資料的流向)而改變,不一定是由左至右或由上至下。 * 不會出現像CSS2排版時的問題,如float須用overflow及clear還原高度的問題;及inline-block須用font-size消除空白和須用vertical-align對齊上方的問題。 ### display: inline-flex; > 設置於父層 * 概念同inline-block,元素會排列在一條直線上;flex則同block,會造成區塊斷行。 * 特性同inline-block,會有小空格問題,並同樣受文字控制屬性影響。 ### flex-direction: row; > 設置於父層 * 預設為row,flex item水平排列,由左往右。 * column,flex item垂直排列,由上往下。 * 當flex-direction的值為column或column-reverse時,flex-basis則代表高度。 ### flex-wrap: wrap; > 設置於父層 * 預設為nowrap,flex item寬度或高度超過父層時,不斷行。 * wrap,flex item寬度或高度超過父層時,斷行。 ### align-content: center; > 設置於父層 * 側軸(預設為垂直方向)的多行對齊。 * 預設為stretch,伸縮行填滿容器的剩餘空間。 * center,伸縮行垂直置中。 * flex-start,伸縮行垂直靠上。 * flex-end,伸縮行垂直靠下。 * space-between,伸縮行平均分配在最上方邊界和最下方邊界。 * space-around,伸縮行上下預留相同空間,平均分配在上方和下方。 * 當flex-direction設定為column時,對齊方式改為左右。 ### align-items: center; > 設置於父層 * 側軸(預設為垂直方向)的單行對齊;僅對單行的flex item有效,超過一行必須用align-content。 * 預設為stretch,伸縮行等高;使用除了stretch以外,其它的align-items屬性,flex item才會彈回原本內容的高度。 * center,伸縮行垂直置中。 * flex-start,伸縮行垂直靠上。 * flex-end,伸縮行垂直靠下。 * beseline,伸縮行對齊文字基線。 ### align-self: auto; > 設置於子層 * 搞特殊,單一伸縮項目垂直對齊。 * 預設為auto,延續父層對align-items的設定。 * 其餘屬性同align-items。 ### justify-content: center; > 設置於父層 * 主軸(預設為水平方向)對齊。 * 預設為flex-start,伸縮行水平靠上。 * flex-end,伸縮行水平靠下。 * center,伸縮行水平置中。 * space-between,伸縮行平均分配在最左方邊界和最右方邊界。 * space-around,伸縮行上下預留相同空間,平均分配在左方和右方。 * 當flex-direction設定為column時,對齊方式改為上下。 ## 子層設定 ### flex-basis: ?px; > 設置於子層 * 預設為auto,依照內容計算寬度。 * 當設定為0,flex item會無視內容寬度,改以flex-grow分配的值,呈現結果。 * flex系統內,預設狀態下,若flex-basis和width同時存在,width會被覆蓋掉。 ### flex-grow: 1; > 設置於子層 * 預設為0,初始狀態不參與分配父層剩餘空間。 * 子元素flex item利用flex-grow屬性,取得父層flex box剩餘空間,並分配份數。 ### flex-shrink: 1; > 設置於子層 * 預設為1,即便子元素flex item寬度總和超過父層flex box寬度,也會被強制壓在父層flex box的寬度內。 * 想突破父層flex box寬度,必須將flex-shrink設為0,代表不參與收縮。 * img已經不屬於flex系統,不受限於父層flex box的寬,故當子元素flex item寬度總和超過父層flex box寬度,將強制破版;必須設置 width: 100% 才會正常。 ### order: ?; > 設置於子層 * 預設為0,可為負值,無須加單位,數字越小位置排序越前面。 ###### tags: `frontend` `cssmonster` [:arrow_right: Back to Front End Homepage :arrow_left:](/S-c0eqQmS16D8tcTx4ae1g)

    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

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    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