劉杰
    • 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
      • Invitee
    • 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
    • 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 Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync 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
Invitee
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 float 相關 ###### tags: `HTML, CSS` **沒有版面設置** 就會像是本文字全塞進去版面,完整地從左邊打字到右邊比較不好閱讀。 所以這邊就會需要用到Display的登場 **關於 "display" 屬性** display 是設計 CSS 版面配置中最重要的屬性,每個 HTML 元素都有一個預設的 display 值,不同的元素屬性會有不同的預設值。大多數的預設值是block以及inline。 1.block 像`<div>,<header>,<footer>,<section>` 2.inline 像`<a>,<span>` 3.none 通常會搭配 JavaScript 一起使用例如使用 滑鼠游標滑過的時候才會SHOW出來之類的功能這個時候沒有SHOW出來的時間就是這個屬性發揮功能。 4.其他 例如 `list-item 和 table` 其他可以參閱這裡: https://developer.mozilla.org/en-US/docs/Web/CSS/display 補充說明 就像我之前說過的,每個元素都有一個預設的 display 屬性,不過你可以隨時隨地地覆蓋這個屬性值 5.inline-block(比較舊知道就好,現在用比較多Flexbox) 跟display-inline很像可是你可以設定width以及height的屬性 ``` .box{ float: left; width: 200px; height: 100px; margin: 1em; } .after-box{ clear: left; } ``` ----- **margin: auto;(水平置中)** ``` #main { width: 600px; margin: 0 auto; } ``` 設定區塊元素的 width 屬性,可以避免該元素從左到右撐滿容器,然後你可以設定左右外邊距(margin-left 與 margin-right)為 auto 來使其水平居中。 **max-width** 在這個屬性的使用之後可以更好的隨著版面大小的改變去處理當瀏覽器視窗小於元素寬度的情況。 第一個圖沒有使用max-width ![](https://i.imgur.com/4tZkdQN.png) 第二張有 ![](https://i.imgur.com/iqKz7cw.png) ------ **關於 Box Model(區塊模型)** 兩個寬度一樣的程式碼跑出來的樣貌卻不太一樣,因為margin跟padding的關係,讓邊界被撐開了。 ``` .simple { width: 500px; margin: 20px auto; } .fancy { width: 500px; margin: 20px auto; padding: 50px; border-width: 10px; } ``` ----- **關於 box-sizing 屬性** 當你設定一個元素樣式為 box-sizing: border-box;,這個**元素的內距和邊框將不會增加元素本身的寬度**。 ``` .simple { width: 500px; margin: 20px auto; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } .fancy { width: 500px; margin: 20px auto; padding: 50px; border: solid blue 10px; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } ``` 這邊可以看到寬度確實是一樣的 ![](https://i.imgur.com/92XbBFd.png) ----- **關於 position 屬性** * static > static 是預設值。任何套用 position: static; 的元素「不會被特別定位」在頁面上特定位置,而是照著瀏覽器預設的配置自動排版在頁面上,所有其他的屬性值都代表該元素會被定位在頁面上。 ``` .static { position: static; } ``` * relative ![](https://i.imgur.com/Qc3cvlu.png) relative是讓第二行程式碼的屬性沿著第一行去做相對的位置 ``` .relative1 { position: relative; } .relative2 { position: relative; top: -20px; left: 20px; background-color: white; width: 500px; } ``` **fixed** > 固定定位(position: fixed)的元素會相對於瀏覽器視窗來定位,這意味著即便頁面捲動,它還是會固定在相同的位置。且利用top 、 right 、 bottom 和 left 屬性來定位。 簡單來說被 fix 住的內容會被固定在頁面上就算滾動也不會跑掉。 ``` .fixed { position: fixed; bottom: 0; right: 0; width: 200px; background-color: white; } ``` **absolute** 通常跟relative一起使用,是絕對位置,當網頁往下拉時,元素也會跟著改變位置,其元素的位置由 top、left、right、bottom 所決定。 ``` .relative { position: relative; width: 600px; height: 400px; } .absolute { position: absolute; top: 120px; right: 0; width: 300px; height: 200px; } ``` ---- **關於 float 屬性** 這個屬性的功能是使文章包裹著圖片,大多數拿來使用排版 ``` img { float: right; margin: 0 0 1em 1em; } ``` ![](https://i.imgur.com/JgEfiq0.png) **clear屬性** > clear 屬性規定元素的哪一側不允許其他浮動元素。 * none * 元素不會向下移動清除之前的浮動 * left * 元素被向下移動用於清除之前的左浮動 * right * 元素被向下移動用於清除之前的右浮動 * both * 元素被向下移動用於清除之前的左右浮動 ![](https://i.imgur.com/r4bAnIg.png) ![](https://i.imgur.com/BFjwg85.png) ![](https://i.imgur.com/bKkY4s0.png) clearfix 這個功能可以調整讓外框包裹的元素自動符合內容的高度(待補充) ``` .clearfix{ overflow: auto; } ``` **百分百寬度** 這樣做相對的百分比的時候就可以讓大小很固定比較不容易跑版因為會照比例走 ``` nav { folat: left; width: 25%; } section{ margin-left: 25%; } ``` **媒體查詢(meadia queries)** 讓格式也可以很好的呈現在手機上面 可以設定條件讓版面小於一定程度的時候display可以改變呈現方式,更可以適用於更多的行動裝置上面 ``` @media screen and (min-width:600px){ nav{ float: left; width: 25%; } section{ margin-left: 25%; } } @media screen and (max-width:599px) { nav li{ display: inline; } } ``` **column** 多欄文字版面配置 ![](https://i.imgur.com/dsjHjqH.png) ``` .three column { padding: 1em; -moz-colum-count: 3; -moz-colum-gap: 1em; -webkit-colum-count: 3; -webkit-column-gap: 1em; column-count: 3; column-gap: 1em; } ``` **flexbox(還沒講)**

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