Movatterモバイル変換


[0]ホーム

URL:


Framework:


Hire Us Get CoreUI PRO all-access

Bootstrap 5 Columns

Columns

Learn how to modify columns with a handful of options for alignment, ordering, and offsetting thanks to our flexbox grid system. Plus, see how to use column classes to manage widths of non-grid elements.

🤖 Looking for the LLM-optimized version?View llm.md

On this page
Heads up! Be sure toread the Grid page first before diving into how to modify and customize your grid columns.

How they work

  • Columns build on the grid’s flexbox architecture. Flexbox means we have options for changing individual columns andmodifying groups of columns at the row level. You choose how columns grow, shrink, or otherwise change.

  • When building grid layouts, all content goes in columns. The hierarchy of CoreUI for Bootstrap’s grid goes fromcontainer to row to column to your content. On rare occasions, you may combine content and column, but be aware there can be unintended consequences.

  • CoreUI for Bootstrap includes predefined classes for creating fast, responsive layouts. Withsix breakpoints and a dozen columns at each grid tier, we have dozens of classes already built for you to create your desired layouts. This can be disabled via Sass if you wish.

Alignment

Use flexbox alignment utilities to vertically and horizontally align columns.

Vertical alignment

One of three columns
One of three columns
One of three columns
One of three columns
One of three columns
One of three columns
One of three columns
One of three columns
One of three columns
html
<divclass="container text-center"><divclass="row align-items-start"><divclass="col">      One of three columns</div><divclass="col">      One of three columns</div><divclass="col">      One of three columns</div></div><divclass="row align-items-center"><divclass="col">      One of three columns</div><divclass="col">      One of three columns</div><divclass="col">      One of three columns</div></div><divclass="row align-items-end"><divclass="col">      One of three columns</div><divclass="col">      One of three columns</div><divclass="col">      One of three columns</div></div></div>
One of three columns
One of three columns
One of three columns
html
<divclass="container text-center"><divclass="row"><divclass="col align-self-start">      One of three columns</div><divclass="col align-self-center">      One of three columns</div><divclass="col align-self-end">      One of three columns</div></div></div>

Horizontal alignment

One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
html
<divclass="container text-center"><divclass="row justify-content-start"><divclass="col-4">      One of two columns</div><divclass="col-4">      One of two columns</div></div><divclass="row justify-content-center"><divclass="col-4">      One of two columns</div><divclass="col-4">      One of two columns</div></div><divclass="row justify-content-end"><divclass="col-4">      One of two columns</div><divclass="col-4">      One of two columns</div></div><divclass="row justify-content-around"><divclass="col-4">      One of two columns</div><divclass="col-4">      One of two columns</div></div><divclass="row justify-content-between"><divclass="col-4">      One of two columns</div><divclass="col-4">      One of two columns</div></div><divclass="row justify-content-evenly"><divclass="col-4">      One of two columns</div><divclass="col-4">      One of two columns</div></div></div>

Column wrapping

If more than 12 columns are placed within a single row, each group of extra columns will, as one unit, wrap onto a new line.

.col-9
.col-4
Since 9 + 4 = 13 > 12, this 4-column-wide div gets wrapped onto a new line as one contiguous unit.
.col-6
Subsequent columns continue along the new line.
html
<divclass="container"><divclass="row"><divclass="col-9">.col-9</div><divclass="col-4">.col-4<br>Since 9 + 4 = 13&gt; 12, this 4-column-wide div gets wrapped onto a new line as one contiguous unit.</div><divclass="col-6">.col-6<br>Subsequent columns continue along the new line.</div></div></div>

Column breaks

Breaking columns to a new line in flexbox requires a small hack: add an element withwidth: 100% wherever you want to wrap your columns to a new line. Normally this is accomplished with multiple.rows, but not every implementation method can account for this.

.col-6 .col-sm-3
.col-6 .col-sm-3
.col-6 .col-sm-3
.col-6 .col-sm-3
html
<divclass="container text-center"><divclass="row"><divclass="col-6 col-sm-3">.col-6 .col-sm-3</div><divclass="col-6 col-sm-3">.col-6 .col-sm-3</div><!-- Force next columns to break to new line --><divclass="w-100"></div><divclass="col-6 col-sm-3">.col-6 .col-sm-3</div><divclass="col-6 col-sm-3">.col-6 .col-sm-3</div></div></div>

You may also apply this break at specific breakpoints with ourresponsive display utilities.

.col-6 .col-sm-4
.col-6 .col-sm-4
.col-6 .col-sm-4
.col-6 .col-sm-4
html
<divclass="container text-center"><divclass="row"><divclass="col-6 col-sm-4">.col-6 .col-sm-4</div><divclass="col-6 col-sm-4">.col-6 .col-sm-4</div><!-- Force next columns to break to new line at md breakpoint and up --><divclass="w-100 d-none d-md-block"></div><divclass="col-6 col-sm-4">.col-6 .col-sm-4</div><divclass="col-6 col-sm-4">.col-6 .col-sm-4</div></div></div>

Reordering

Order classes

Use.order- classes for controlling thevisual order of your content. These classes are responsive, so you can set theorder by breakpoint (e.g.,.order-1.order-md-2). Includes support for1 through5 across all six grid tiers.

First in DOM, no order applied
Second in DOM, with a larger order
Third in DOM, with an order of 1
html
<divclass="container text-center"><divclass="row"><divclass="col">      First in DOM, no order applied</div><divclass="col order-5">      Second in DOM, with a larger order</div><divclass="col order-1">      Third in DOM, with an order of 1</div></div></div>

There are also responsive.order-first and.order-last classes that change theorder of an element by applyingorder: -1 andorder: 6, respectively. These classes can also be intermixed with the numbered.order-* classes as needed.

First in DOM, ordered last
Second in DOM, unordered
Third in DOM, ordered first
html
<divclass="container text-center"><divclass="row"><divclass="col order-last">      First in DOM, ordered last</div><divclass="col">      Second in DOM, unordered</div><divclass="col order-first">      Third in DOM, ordered first</div></div></div>

If you need more.order-* classes, you can add new ones by modifying our$utilities Sass map.Read our Sass maps and loops docs orour Modify utilities docs for details.

$utilities:map-merge($utilities,("order":map-merge(map-get($utilities,"order"),(values:map-merge(map-get(map-get($utilities,"order"),"values"),(6:6,// Add a new `.order-{breakpoint}-6` utilitylast:7// Change the `.order-{breakpoint}-last` utility to use the next number)),),),));###OffsettingcolumnsYoucanoffsetgridcolumnsintwoways:ourresponsive`.offset-`gridclassesandour[marginutilities](/utilities/spacing/).Gridclassesaresizedtomatchcolumnswhilemarginsaremoreusefulforquicklayoutswherethewidthoftheoffsetisvariable.####OffsetclassesMovecolumnstotherightusing`.offset-md-*`classes.Theseclassesincreasetheleftmarginofacolumnby`*`columns.Forexample,`.offset-md-4`moves`.col-md-4`overfourcolumns.
.col-md-4
.col-md-4 .offset-md-4
.col-md-3 .offset-md-3
.col-md-3 .offset-md-3
.col-md-6 .offset-md-3
html
<divclass="container text-center"><divclass="row"><divclass="col-md-4">.col-md-4</div><divclass="col-md-4 offset-md-4">.col-md-4 .offset-md-4</div></div><divclass="row"><divclass="col-md-3 offset-md-3">.col-md-3 .offset-md-3</div><divclass="col-md-3 offset-md-3">.col-md-3 .offset-md-3</div></div><divclass="row"><divclass="col-md-6 offset-md-3">.col-md-6 .offset-md-3</div></div></div>
.col-sm-5 .col-md-6
.col-sm-5 .offset-sm-2 .col-md-6 .offset-md-0
.col-sm-6 .col-md-5 .col-lg-6
.col-sm-6 .col-md-5 .offset-md-2 .col-lg-6 .offset-lg-0
html
<divclass="container text-center"><divclass="row"><divclass="col-sm-5 col-md-6">.col-sm-5 .col-md-6</div><divclass="col-sm-5 offset-sm-2 col-md-6 offset-md-0">.col-sm-5 .offset-sm-2 .col-md-6 .offset-md-0</div></div><divclass="row"><divclass="col-sm-6 col-md-5 col-lg-6">.col-sm-6 .col-md-5 .col-lg-6</div><divclass="col-sm-6 col-md-5 offset-md-2 col-lg-6 offset-lg-0">.col-sm-6 .col-md-5 .offset-md-2 .col-lg-6 .offset-lg-0</div></div></div>
####MarginutilitiesWiththemovetoflexboxinv4,youcanusemarginutilitieslike`.me-auto`toforcesiblingcolumnsawayfromoneanother.
.col-md-4
.col-md-4 .ms-auto
.col-md-3 .ms-md-auto
.col-md-3 .ms-md-auto
.col-auto .me-auto
.col-auto
html
<divclass="container text-center"><divclass="row"><divclass="col-md-4">.col-md-4</div><divclass="col-md-4 ms-auto">.col-md-4 .ms-auto</div></div><divclass="row"><divclass="col-md-3 ms-md-auto">.col-md-3 .ms-md-auto</div><divclass="col-md-3 ms-md-auto">.col-md-3 .ms-md-auto</div></div><divclass="row"><divclass="col-auto me-auto">.col-auto .me-auto</div><divclass="col-auto">.col-auto</div></div></div>
##StandalonecolumnclassesThe`.col-*`classescanalsobeusedoutsidea`.row`togiveanelementaspecificwidth.Whenevercolumnclassesareusedasnondirectchildrenofarow,thepaddingsareomitted.
.col-3: width of 25%
.col-sm-9: width of 75% above sm breakpoint
html
<divclass="col-3 bg-light p-3 border">  .col-3: width of 25%</div><divclass="col-sm-9 bg-light p-3 border">  .col-sm-9: width of 75% above sm breakpoint</div>
Theclassescanbeusedtogetherwithutilitiestocreateresponsivefloatedimages.Makesuretowrapthecontentina[`.clearfix`](/helpers/clearfix/)wrappertoclearthefloatifthetextisshorter.
PlaceholderResponsive floated image

A paragraph of placeholder text. We're using it here to show the use of the clearfix class. We're adding quite a few meaningless phrases here to demonstrate how the columns interact here with the floated image.

As you can see the paragraphs gracefully wrap around the floated image. Now imagine how this would look with some actual content in here, rather than just this boring placeholder text that goes on and on, but actually conveys no tangible information at. It simply takes up space and should not really be read.

And yet, here you are, still persevering in reading this placeholder text, hoping for some more insights, or some hidden easter egg of content. A joke, perhaps. Unfortunately, there's none of that here.

html
<divclass="clearfix"><imgsrc="..."class="col-md-6 float-md-end mb-3 ms-md-3"alt="..."><p>    A paragraph of placeholder text. We're using it here to show the use of the clearfix class. We're adding quite a few meaningless phrases here to demonstrate how the columns interact here with the floated image.</p><p>    As you can see the paragraphs gracefully wrap around the floated image. Now imagine how this would look with some actual content in here, rather than just this boring placeholder text that goes on and on, but actually conveys no tangible information at. It simply takes up space and should not really be read.</p><p>    And yet, here you are, still persevering in reading this placeholder text, hoping for some more insights, or some hidden easter egg of content. A joke, perhaps. Unfortunately, there's none of that here.</p></div>

[8]ページ先頭

©2009-2025 Movatter.jp