Eze ThankGod
    • 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
    # Working With Multiple Columns in CSS ## Introduction The `CSS` multi-column layout lets you specify the number of columns you want an element to be divided into quickly and efficiently. This article will guide you on creating `column-to-column`, `gap sizes` between columns, and `column dividing lines`, along with their appearance. ### What is a CSS multi-column layout? A [`CSS multi-column layout`](https://www.w3schools.com/css/css3_multiple_columns.asp) is a style in which content divides into multiple columns, similar to a newspaper or magazine layout. This occurs by creating a print-inspired layout with the web's flexibility, enabling content flow, as seen in magazines and newspapers, without `floating boxes`. ### What are the benefits of CSS multi-columns? There are several benefits to using `CSS multi-column layout`. Here are some benefits of using it: - It creates a more visually exciting and engaging design for a webpage. - You can create a multi-column layout with just a few lines of code, and it is easy to customize the number of columns, the `gap` between columns, and the width of the columns. - It is `responsive`, meaning it can adjust to the screen size and device viewed, creating layouts that look good on desktop and mobile devices. - It improves better readability of a webpage by breaking up the content into smaller, more manageable chunks, making it easier for users to scan and read the content. - Better use of space, that is, you can use the available space on the screen, especially on smaller screens where a single-column layout may take up too much space. - It helps to balance a page's layout and create a more pleasing design. - It reduces the amount of scrolling required to view the content, improving the overall user experience. - It creates magazine-style or newspaper-style layouts. - It is useful for presenting text-heavy content, such as news or long-form articles. ## Understanding Multi-column Properties and their uses In CSS, a multi-column layout is a feature that allows you to divide a web page into multiple columns, similar to a newspaper or magazine layout. It helps create a more visually exciting and easy-to-read format for text-heavy pages. The properties used to control multi-column layout are `column count`, `column width`, `column gap`, `column rule style`, `column rule width`, `column-rule-color`, `column rule` and `column-span`. Note: To use the multi-column layout, you need to specify the number of columns or the width of the columns for the element you want to divide into multiple columns and then set the appropriate values for the other properties as needed. Here are the multi-column properties and their uses: ### Column-count [`Column-count` ](https://www.w3schools.com/cssref/css3_pr_column-count.php)is a CSS property used to set the number of columns a component should be divided into. It is used for splitting a block-level elements content into columns, similar to how the text in a newspaper divides into columns. Therefore, it sets the number of columns using the `column-count` property. For example: ```html <!DOCTYPE html> <html> <head> <style> body { border: 1px solid blue; } h1 { text-align: center; } .paper { column-count: 4; text-align: justify; font-weight: bold; font-size: 24px; } </style> </head> <body> <h1>Multiple Columns</h1> <div class="paper"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut pharetra dui et tortor maximus, quis feugiat nulla lobortis. Mauris vestibulum blandit pretium. Sed dolor dui, molestie rhoncus felis nec, porta posuere orci. Donec efficitur orci et auctor volutpat. Aenean pulvinar libero et quam rutrum, eget faucibus augue scelerisque. Nulla sollicitudin ornare ipsum eu interdum. Nunc vitae consequat tortor. Proin at pulvinar mi. Nunc venenatis quam justo, in gravida ex cursus eu. Mauris aliquet in elit vel sagittis. Cras a dapibus turpis. Morbi malesuada at turpis et imperdiet. Aliquam lacinia, velit vel volutpat scelerisque, ex diam laoreet justo, sed lobortis turpis enim nec erat. Nulla vulputate vitae quam nec aliquam. Integer egestas posuere eros, ac bibendum neque suscipit quis. Cras mattis nisl porta congue mollis. Quisque facilisis suscipit lectus, ac tristique metus. Iaculis sit amet. Nam varius arcu a nibh tincidunt aliquam feugiat in felis. Phasellus a massa elit. Vivamus dapibus vestibulum vehicula. </div> </body> </html> ``` Here is the outcome: ![](https://i.imgur.com/qOa79my.png) Notice that the CSS sets an element with the class "paper" to have four columns. ### Column-gap The [`column gap`](https://developer.mozilla.org/en-US/docs/Web/CSS/column-gap) is a `CSS` property that sets the size of the gap between columns in a multi-column layout. Therefore, you can set it by using a length value, such as `px`, `em`, or `rem`, or the keyword `normal`, which sets the gap to the default value. In addition, you can use it simultaneously with `column-count` or `column-width` properties. Examples: ```CSS <style> body { border: 1px solid blue; } h1 { text-align: center; } .paper { column-count: 4; column-gap: 100px; text-align: justify; font-weight: bold; font-size: 24px; } </style> ``` Here is the result: ![](https://i.imgur.com/GdEruDO.png) Notice that the CSS creates a gap of 100 pixels between the columns. ### Column-rule-style [`Column-rule-style`](https://developer.mozilla.org/en-US/docs/Web/CSS/column-rule-style) is a CSS property that sets the style of the line that separates columns in a multi-column layout. Therefore, you can set it to one of the following values: - `Solid`: A solid line between columns. - `Dotted`: A line made of dots between columns. - `Dashed`: A line made of short dashes between columns. - `Double`: A double line between columns. Examples of how to set the column rule style: **A solid rule between the columns** You can set a `solid` rule between the columns. For example: ```CSS <style> body { border: 1px solid blue; } h1 { text-align: center; } .paper { column-count: 4; column-rule-style: solid; text-align: justify; font-weight: bold; font-size: 24px; } </style> ``` Here is the outcome: ![](https://i.imgur.com/rEhAbD2.png) Notice a solid line between the columns. **A dotted rule between columns** You can set a `dotted` rule between the columns. For example: ```CSS <style> body { border: 1px solid blue; } h1 { text-align: center; } .paper { column-count: 4; column-rule-style: dotted; text-align: justify; font-weight: bold; font-size: 24px; } </style> ``` Here is the result: ![](https://i.imgur.com/ZQXKUs4.png) Notice a dotted line between the columns. **A dashed rule between the column** You can also use the `column-rule-style` property to set a `dashed` rule between the columns. For example: ```CSS <style> body { border: 1px solid blue; } h1 { text-align: center; } .paper { column-count: 4; column-rule-style: dashed; text-align: justify; font-weight: bold; font-size: 24px; } </style> ``` Here is the outcome: ![](https://i.imgur.com/j3d6NtV.png) Notice a dashed rule between columns. **A double rule between the columns** You can set a `double` rule between the columns. For example: ```CSS <style> body { border: 1px solid blue; } h1 { text-align: center; } .paper { column-count: 4; column-rule-width: 10px; column-rule-style: double; text-align: justify; font-weight: bold; font-size: 24px; } </style> ``` Here is the result: ![](https://i.imgur.com/4YketMn.png) Notice a double rule between columns. ### Column-rule-width [`Column rule width`](https://www.quackit.com/css/css3/properties/css_column-rule-width.cfm) is a CSS property that specifies the width of the rule or line between the columns in a multi-column layout. Therefore, you can set the width in a length value (e.g. `px`, `em`, `rem`). The default value for column rule width is `medium`, equivalent to a width of 3px. In addition, you can use this property with the `column-rule-style` and `column-rule-color` properties to control the appearance of the column rule. For example: ```CSS <style> body { border: 1px solid blue; } h1 { text-align: center; } .paper { column-count: 4; column-rule-style: solid; column-rule-width: 10px; text-align: justify; font-weight: bold; font-size: 24px; } </style> ``` Here is the outcome: ![](https://i.imgur.com/ZKZzUu4.png) Notice that the `column rule width` between the columns was set to `10 pixels`, and the outcome is what you saw in the picture. ### Column-rule-color The [`column rule color`](https://www.w3schools.com/cssref/css3_pr_column-rule-color.php) is a CSS property that sets the color of the rule (line) marked between columns in a multi-column layout. Therefore, you can style the rule between the columns with a width, style, and color. Example: ```CSS <style> body { border: 1px solid blue; } h1 { text-align: center; } .paper { column-count: 4; column-rule-style: solid; column-rule-width: 5px; column-rule-color: red; text-align: justify; font-weight: bold; font-size: 24px; } </style> ``` Here is the result: ![](https://i.imgur.com/KEYhuVY.png) Notice that the `column rule color` was set between the columns as `red`. ### Column-rule The [`column rule`](https://developer.mozilla.org/en-US/docs/Web/CSS/column-rule) is a CSS property specifying a line separating columns in a multi-column layout. The property is a shorthand for the column-rule-width, column-rule-style, and column-rule-color properties. There you can use the column rule property to control the appearance of the width, style and color of the rule or line that separates columns in a multi-column layout. For example: ```CSS <style> body { border: 1px solid blue; } h1 { text-align: center; } .paper { column-count: 4; column-rule: 13px solid green; text-align: justify; font-weight: bold; font-size: 24px; } </style ``` Here is the result: ![](https://i.imgur.com/TgoWvBA.png) The above CSS rule would create a `13px` wide `solid` green line between columns. ### Column-span The [`CSS column-span`](https://www.w3schools.com/cssref/css3_pr_column-span.php) property specifies how many columns an element should span across in a multi-column layout. This property can be set to a positive integer value, which indicates the number of columns the part should span across. You can also set it to the keyword `all`, which suggests that the element should span across all columns in the container. It is essential to note that the `column span` only works if the element is positioned within a block formatting context. Therefore, the element must be a block-level element and a child of a multi-column container. Example: ```html <!DOCTYPE html> <html> <head> <style> body { border: 1px solid blue; } .paper { column-count: 4; column-rule: 1px solid green; text-align: justify; font-weight: bold; font-size: 24px; } h1 { column-span: all; } </style> </head> <body> <div class="paper"> <h1>Column Span</h1> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut pharetra dui et tortor maximus, quis feugiat nulla lobortis. Mauris vestibulum blandit pretium. Sed dolor dui, molestie rhoncus felis nec, porta posuere orci. Donec efficitur orci et auctor volutpat. Aenean pulvinar libero et quam rutrum, eget faucibus augue scelerisque. Nulla sollicitudin ornare ipsum eu interdum. Nunc vitae consequat tortor. Proin at pulvinar mi. Nunc venenatis quam justo, in gravida ex cursus eu. Mauris aliquet in elit vel sagittis. Crasa dapibus turpis. Morbi malesuada at turpis et imperdiet. Aliquam lacinia, velit vel volutpat scelerisque, ex diam laoreet justo, sed lobortis turpis enim nec erat. Nulla vulputate vitae quam nec aliquam. Integer egestas posuere eros, ac bibendum neque suscipit quis. Cras mattis nisl porta congue mollis. Quisque facilisis suscipit lectus, ac tristique metus iaculis sit amet. Nam varius arcu a nibh tincidunt aliquam feugiat in felis. Phasellus a massa elit. Vivamus dapibus vestibulum vehicula. </div> </body> </html> ``` Here is the result: ![](https://i.imgur.com/15MJlJY.png) Notice that it spans across all four columns as it is set to `all`. #### Setting a column 'span' to none. Example: ```CSS <style> body { border: 1px solid blue; } .paper { column-count: 4; column-rule: 1px solid green; text-align: justify; font-weight: bold; font-size: 24px; } h1 { column-span: none; } </style> ``` Here is the result: ![](https://i.imgur.com/9tfMRky.png) ### Column-width The [`column width`](https://css-tricks.com/almanac/properties/c/column-width/) property in CSS specifies the minimum or optimal width for a multi-column layout. Therefore, you can use it with the `column-count` property, which determines the maximum number of columns, to create a flexible multi-column layout. If the `column width` is not set clearly, the columns will be sized based on their content. You can set the column width using a length value (such as pixels), or the `auto` keyword, which will cause the columns to be sized based on the container's width. For example: ```CSS <style> body { border: 1px solid blue; } h1 { text-align: center; } .paper { column-width: 100px; font-weight: bold; } </style> ``` Here is the result: ![](https://i.imgur.com/YCbNvOU.png) The above example determines that the suggested optimal width for the columns should be 100px. #### Setting multiple responsive columns. You can use the `column-count` property to [create multiple columns](https://css-tricks.com/guide-responsive-friendly-css-columns/) in CSS for responsive design. Example: ```CSS <style> body { border: 1px solid blue; } h1 { text-align: center; } .paper { -webkit-column-count: 4; -moz-column-count: 4; column-count: 4; -webkit-column-gap: 40px; -moz-column-gap: 40px; column-gap: 40px; font-weight: bold; font-size: 18px; text-align: justify; } @media (max-width: 600px) { .paper { -webkit-column-count: 3; -moz-column-count: 3; column-count: 3; } } </style> ``` Here is the result: On large screens more than 600px: ![](https://i.imgur.com/K8CtXmZ.png) On screens smaller than 600px: ![](https://i.imgur.com/FiW7u5a.png) The above will create 4 columns on large screens and 3 on screens smaller than 600px. ## Browser support The CSS3 multi-column layout module is supported by most modern web browsers, such as: - Google Chrome - Mozilla Firefox - Apple Safari - Microsoft Edge ## Conclusion CSS multi-column layouts are beneficial in our web pages as they can improve the readability of a web page by breaking up the content into smaller parts and enabling users to scan and read the content easily. You can use these directions to create a multi-column layout with merely a few lines of code, and it is effortless to customize the number of columns, the gap between columns, and the width of the columns in your web development tasks.

    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