RZ-Huang
    • 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
    • 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 Versions and GitHub Sync Note Insights 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # CSS Preprocessor ###### tags: `css`、`css preprocessor` ## 簡介 簡單說就是用程式化的方式來寫 CSS,讓撰寫 CSS 的語法的時候比較有歸納性、好維護性。 常用的 CSS Preprocessor 有以下三套軟體: 1. SCSS/Sass 2. Less 3. Stylus 基本上每套的語法都差不多,只要會其中一套其它很快可以上手。 而 SCSS 和 Sass 可視為一套,差別只在於 Sass 的 CSS 語法沒有 `{}` 和 `;` 的符號,如下範例都是一樣的效果與結果: #### Scss ``` .box { background: blue; } ``` #### Sass ``` .box backgroud: blue ``` ## Sass 接著下面的語法皆採用 Sass 這套軟體來熟悉 CSS Preprocessor。 ### 安裝方式 可參考官網:https://sass-lang.com/install 我是採用 node.js 的 npm 套件來安裝,語法為: `npm install -g sass` #### 如何知道安裝成功 Sass:在 CLI 使用 `sass -v` 或是 `sass --version` ### 語法 #### Variables 變數 ``` $brand-color: blue .box background: $brand-color .list background: $brand-color ``` 使用`$`的符號作為變數的前綴符號來命名,而使用變數的好處就跟寫其它程式語言一樣,當我們需要使用這個變數就把這個變數呼叫出來,而在 CSS Preprocessor 的變數即為它所代表的 css 意思。 #### Compile 到 CSS 檔案 可以使用 `sass 'sass的檔案' 'css的檔案'` 語法,把在 sass 檔案打好的語法 compile 到 css 檔案裡去,非常地方便 像上面變數的例子,假設 sass 檔案叫做 index.sass;css 檔案叫做 index.css,就可以輸入`sass index.sass index.css`。而 index.css 的檔案內容就會變成下面這樣: ``` .box { background: blue; } .list { background: blue; } ``` 另外如果想要自動 compile 同步的話,可以輸入`sass --watch index.sass index.css` ### Nesting 巢狀 就是可以寫成階梯式那樣,外層會涵蓋所有內層的屬性,如下為 index.sass 的內容: ``` .box display: none .btn width: 100px .text color: green .label font-size: 12px ``` compile 到 index.css 的結果: ``` .box { display: none; } .box .btn { width: 100px; } .box .btn .text { color: green; } .box .btn .label { font-size: 12px; } /*# sourceMappingURL=index.css.map */ ``` ### Parent 父層 使用`&`的符號代替父層的名稱,如下範例為 index.sass 的內容: ``` $brand-color: blue .card background: $brand-color &__wrapper width: 100% &__list height: 100px &--disabled display: none ``` compile 到 index.css 的結果: ``` .card { background: blue; } .card__wrapper { width: 100%; } .card__list { height: 100px; } .card__list--disabled { display: none; } /*# sourceMappingURL=index.css.map */ ``` ### Mixins 很像 function 的用法,把常用的結構放在 Mixins 裡,只要呼叫就可以一併呈現,以下為 index.sass 的內容: ``` @mixin border-radius($radius) -webkit-border-radius: $radius -moz-border-radius: $radius -ms-border-radius: $radius border-radius: $radius .card @include border-radius(10px) ``` `@mixin` 就是類似 function 的宣告,而 `border-radius` 則是這個 mixin 的名稱,`($radius)` 就像 function 的參數一樣。當要呼叫 mixin 則是輸入`@include mixin名稱(引數)` compile 到 index.css 的結果: ``` .card { -webkit-border-radius: 10px; -moz-border-radius: 10px; -ms-border-radius: 10px; border-radius: 10px; } /*# sourceMappingURL=index.css.map */ ``` #### 也可以做四則運算: ``` @mixin border-radius($radius) -webkit-border-radius: $radius*2 -moz-border-radius: $radius*2 -ms-border-radius: $radius border-radius: $radius .card @include border-radius(10px) ``` compile 到 index.css 的結果: ``` .card { -webkit-border-radius: 20px; -moz-border-radius: 20px; -ms-border-radius: 10px; border-radius: 10px; } /*# sourceMappingURL=index.css.map */ ``` ### _XXX.SCSS 的檔案應用 >_color.scss 它的檔名是以 _ 開頭,就是用來被匯入的css檔,裡面通常會是定義用於 scss 檔的變數,我們在這裡定義一些顏色。 #### 參考資料 1. [Webpack 實作入門2:打包 CSS / SCSS 與 加入 Bootstrap](http://www.mrmu.com.tw/2017/08/18/webpack-tutorial2-css-scss/) #### 延伸資料 1. [你可能不知道的 Sass 技巧](https://medium.com/d-d-mag/%E4%BD%A0%E5%8F%AF%E8%83%BD%E4%B8%8D%E7%9F%A5%E9%81%93%E7%9A%84-sass-%E6%8A%80%E5%B7%A7-c97d4d5e0fc4) 2. [30天掌握Sass語法](https://ithelp.ithome.com.tw/users/20040221/ironman/562)

    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