Fortes Huang
  • NEW!
    NEW!  Connect Ideas Across Notes
    Save time and share insights. With Paragraph Citation, you can quote others’ work with source info built in. If someone cites your note, you’ll see a card showing where it’s used—bringing notes closer together.
    Got it
      • 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
    --- title: '2020/03/04 Sass/Scss 教學筆記: 如何製作 iconFonts' disqus: hackmd --- 2020/03/04 Sass/Scss 教學筆記: 如何製作 iconFonts === 綱要 [TOC] 註冊Fontastic === ![](https://i.imgur.com/4LFzDeM.png) http://app.fontastic.me/ Fontastic是個線上圖示轉字體服務的網站,可以上傳自己製作的svg圖檔並管理集合。 也提供轉換成CSS樣式以前的命名模式編輯,打包下載時可以直接跟著範例網頁以class的方式或者data-attribute調用圖示。 --- 關於製作 Font SVG 這檔事的坑 === 繪製icon的軟體,只要是能匯出svg格式的都可以,推薦Adobe Illustrator和Sketch等。 但要將icon轉換成字體,一定會有些固定的細節需要注意: :::info ・必須是RGB純黑色#000000,且不能有遮色片 ・必須對齊中心點以免日後發生需要額外寫 padding 的慘劇 ・必須將所有外觀線條、字體轉外框,形狀也要合併為單一圖層整體色塊 ::: ![](https://i.imgur.com/tAH0Pg5.png) 假如不小心手殘或手賤亂調色票、沒轉外框、沒合併形狀,轉出SVG上傳到 Fontastic 就會發生這種恐怖的事情: ![](https://i.imgur.com/qeOUxBj.png) 製作方式 === ![](https://i.imgur.com/8CMERab.png) ![](https://i.imgur.com/iU5OTMV.png) ![](https://i.imgur.com/j4aeasA.png) ![](https://i.imgur.com/nTiqpWD.png) 下載之前可以在CUSTOMIZE編輯class name和使用`data-attribute`時的MAPPING字元,這邊推薦大家切換成PUA模式。 ![](https://i.imgur.com/EV65Rwj.png) 選擇PUBLISH後可以預覽一下class name和MAPPING: ![](https://i.imgur.com/OREJehC.png) ![](https://i.imgur.com/H6jn2D6.png) 下載解壓縮後會看見一份CSS檔和一個html、以及一個fonts目錄。 ![](https://i.imgur.com/MTNQ5zo.png) 直接將CSS的內容複製到新的Scss檔,接下來我們就可以在網頁中使用它們: ```css= @charset "UTF-8"; @font-face { font-family: "iconfonts"; src:url("fonts/iconfonts.eot"); src:url("fonts/iconfonts.eot?#iefix") format("embedded-opentype"), url("fonts/iconfonts.woff") format("woff"), url("fonts/iconfonts.ttf") format("truetype"), url("fonts/iconfonts.svg#iconfonts") format("svg"); font-weight: normal; font-style: normal; } [data-icon]:before { font-family: "iconfonts" !important; content: attr(data-icon); font-style: normal !important; font-weight: normal !important; font-variant: normal !important; text-transform: none !important; /* speak是設置聲音輸出屬性,這邊其實不需要 */ speak: none; line-height: 1; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } [class^="app-"]:before, [class*=" app-"]:before { font-family: "iconfonts" !important; font-style: normal !important; font-weight: normal !important; font-variant: normal !important; text-transform: none !important; speak: none; line-height: 1; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } /* 假如你增加了icon的數量,就必須重新再下載一次,而這裡的編號也會跟著異動 */ .icons-key:before { content: "\61"; } .icons-earphone:before { content: "\62"; } .icons-heart:before { content: "\63"; } .icons-dialogue:before { content: "\64"; } .icons-music:before { content: "\65"; } .icons-lock:before { content: "\66"; } .icons-node:before { content: "\67"; } .icons-piechart:before { content: "\68"; } .icons-search:before { content: "\69"; } .icons-speaker:before { content: "\6a"; } .icons-star:before { content: "\6b"; } ``` ```sass= /* variable.scss */ /* 還可以替這些icon染色 */ $iconFontsColors: 'info', 'success', 'error', 'warning'; @mixin iconFontsColor($currentColor) { [class^="app-"]:before, [class*=" app-"]:before { @if $currentColor == 'info' { color: #0066FF; } @else if $currentColor == 'success' { color: #FFEE99; } @else if $currentColor == 'error' { color: #FF3333; } @else if $currentColor == 'warning' { color: #77FF00; } } } .tabs { .button { /* 調用時根據'info', 'success', 'error', 'warning' 帶出不同結果 */ @include iconFontsColor('info'); } } ``` ```css= /* 編譯後的CSS */ /* iconFontsColor指定'info'的結果 */ .tabs .button [class^=app-]:before, .tabs .button [class*=" app-"]:before { color: #0066FF; } ``` ```sass= /* variable.scss */ /* 用data-attribute的染色寫法 */ $iconFontsColors: 'info', 'success', 'error', 'warning'; @each $currentColor in $iconFontsColors { .tabs { &[data-iconColor=#{$currentColor}]{ .button { &[data-icon]:before { @if $currentColor == 'info' { color: #0066FF; } @else if $currentColor == 'success' { color: #FFEE99; } @else if $currentColor == 'error' { color: #FF3333; } @else if $currentColor == 'warning' { color: #77FF00; } } } } } } ``` ```css= /* 編譯後的CSS */ .tabs[data-iconColor=info] .button[data-icon]:before { color: #0066FF; } .tabs[data-iconColor=success] .button[data-icon]:before { color: #FFEE99; } .tabs[data-iconColor=error] .button[data-icon]:before { color: #FF3333; } .tabs[data-iconColor=warning] .button[data-icon]:before { color: #77FF00; } ``` :::info 還記不記得之前提過,當你的style class name命名是一個系列,比如「block-container」、「block-row」,我們就可以利用比對選擇器處理: [class^="block-"] >> 表示匹配開頭有"block-"的所有class name [class*=" block-"] >> 表示子元素有"block-"的所有class name ::: ```htmlmixed= <ul> <li> <!-- 調用的方法也非常直覺,可以用class name的方式,也能用data-attribute --> <div class="icon app-star"></div> <p>class key</p> </li> <li> <div class="icon" data-icon="&#xe00c;"></div> <p>data attribute star</p> </li> </ul> ``` --- 本日後記 === 我們之所以使用iconFonts的最大理由,就是考慮每個User的網速,和減少對Server端存取的次數,這種字體檔的體積也比一般英數字的種類來的更小,畢竟對於User來說,能縮短等待時間還是有加分的。 --- ###### tags: `Scss` `iconFonts` `fontastic`

    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