


A brief discussion on how to sort and offset columns in Bootstrap grid layout
This article will take you through the sorting and offset issues of grid columns in Bootstrap grid layout, and see how the grid columns are sorted and offset. I hope it will be helpful to you!
1. Column sorting
1.1 Column reordering example
Sometimes for some reason (such as SEO), The visual effect we need to display is different from the sequential search shown in the source code. For example, the web page is divided into two parts: left and right. We need the navigation on the left and the latest article list on the right. However, for SEO reasons, we want the search engine spiders to The first thing to get is the latest article list. At this time we need to reorder the columns. [Related recommendation: "bootstrap Tutorial"]
Of course, you may have other reasons to do this.
<!doctype html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="keywords" content=""> <meta name="description" content=""> <link href="bootstrap5/bootstrap.min.css" rel="stylesheet"> <title>列的排序</title> </head> <body> <div class="container"> <div class="row row-cols-3"> <div class="col-9 order-2"> <h5 id="最新文章列表">最新文章列表</h5> <ol> <li>文章标题 作者 发布日期</li> <li>文章标题 作者 发布日期</li> <li>文章标题 作者 发布日期</li> <li></li> <li></li> </ul> </div> <div class="col-3 order-1"> <h5 id="站点导航">站点导航</h5> <ul> <li>随手记</li> <li>心情点滴</li> <li>职场人士</li> </ul> </div> </div> </div> <script src="bootstrap5/bootstrap.bundle.min.js"></script> </body> </html>
**Isn’t it amazing? Next, I will give another example to introduce the sorting rules in detail. **
<!doctype html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="keywords" content=""> <meta name="description" content=""> <link href="bootstrap5/bootstrap.min.css" rel="stylesheet"> <style> .col {height: 50px; border: 1px solid #000;} h5{text-align: center;} </style> <title>网格行列演示</title> </head> <body> <h5 id="默认顺序">默认顺序</h5> <div class="container"> <div class="row row-cols-3"> <div class="col">1</div> <div class="col">2</div> <div class="col">3</div> <div class="col">4</div> <div class="col">5</div> <div class="col">6</div> <div class="col">7</div> <div class="col">8</div> </div> </div> <h5 id="使用数字调整顺序">使用数字调整顺序</h5> <div class="container"> <div class="row row-cols-3"> <div class="col">1</div> <div class="col order-1">2 order-1</div> <div class="col order-5">3 order-5</div> <div class="col order--1">4 order--1</div> <div class="col order-6">5 order-6</div> <div class="col order-0">6 order-0</div> <div class="col order-4">7 order-4</div> <div class="col">8</div> </div> </div> <h5 id="使用单词调整顺序">使用单词调整顺序</h5> <div class="container"> <div class="row row-cols-3"> <div class="col">1</div> <div class="col order-last">2 order-last</div> <div class="col">3</div> <div class="col order-first">4 order-first</div> <div class="col order-first">5 order-first</div> <div class="col">6</div> <div class="col">7</div> <div class="col">8</div> </div> </div> <h5 id="数字和单词调整顺序">数字和单词调整顺序</h5> <div class="container"> <div class="row row-cols-3"> <div class="col">1</div> <div class="col order-last">2 order-last</div> <div class="col order-5">3 order-5</div> <div class="col order-3">4 order-3</div> <div class="col order-first">5 order-first</div> <div class="col order-2">6 order-2</div> <div class="col order-1">7 order-1</div> <div class="col">8</div> </div> </div> <script ></script> </body> </html>
Specific effect
1.2 Use numerical sorting
Use the order-*
class to control content Visual order, where *
is the number 1-5. We are very sorry that only these five numbers are supported. If you use other numbers, it will not work. According to the example table above, you can see:
The first table is the case where sorting is not used and is sorted directly in order.
Using numbers other than 1-5 has no effect. It is still displayed in its original order, such as the original 4, 5, and 6 columns.
Columns that use numbers are sorted behind columns that are not sorted, sorted according to the sorting numbers from small to large
Sort numbers do not need to be used in order , for example, 2 and 3 are not used in the above example.
1.3 Using word sorting
is very simple to use word sorting. There are only two classes, order-first and .order-last, which represent the beginning and the end respectively. From the example As can be seen in , word sorting can be combined with numeric sorting, and word sorting has a higher priority than numeric and default sorting.
2. Column offset
2.1 Use .offset-class
Use offset-md-*
class to move the column to the right*
grids, these classes are implemented by increasing the left margin of the column by *
grids.
The other columns following the offset column are arranged with the offset column as the new starting point.
The code is still used to demonstrate the following:
<!doctype html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="keywords" content=""> <meta name="description" content=""> <link href="bootstrap5/bootstrap.min.css" rel="stylesheet"> <style> [class^="col-"] {height: 50px; border: 1px solid #000;} h5{text-align: center;} </style> <title>列的排序</title> </head> <body> <div class="container"> <div class="row"> <div class="col-md-1">1</div> <div class="col-md-1">2</div> <div class="col-md-1">3</div> <div class="col-md-1">4</div> <div class="col-md-1">5</div> <div class="col-md-1">6</div> <div class="col-md-1">7</div> <div class="col-md-1">8</div> <div class="col-md-1">9</div> <div class="col-md-1">10</div> <div class="col-md-1">11</div> <div class="col-md-1">12</div> </div> <div class="row"> <div class="col-md-4">.col-md-4</div> <div class="col-md-4 offset-md-4">.col-md-4 .offset-md-4</div> </div> <div class="row"> <div class="col-md-3 offset-md-3">.col-md-3 .offset-md-3</div> <div class="col-md-3 offset-md-3">.col-md-3 .offset-md-3</div> </div> <div class="row"> <div class="col-md-6 offset-md-3">.col-md-6 .offset-md-3</div> </div> </div> <script ></script> </body> </html>
The display results are as follows
#.offset-class also supports responsive layout. Here is an example. You can check the effect yourself and deepen your understanding.
<!doctype html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="keywords" content=""> <meta name="description" content=""> <link href="bootstrap5/bootstrap.min.css" rel="stylesheet"> <style> [class^="col-"] {height: 50px; border: 1px solid #000;} h5{text-align: center;} </style> <title>列的排序</title> </head> <body> <div class="container"> <div class="row row-cols-12"> <div class="col-1">1</div> <div class="col-1">2</div> <div class="col-1">3</div> <div class="col-1">4</div> <div class="col-1">5</div> <div class="col-1">6</div> <div class="col-1">7</div> <div class="col-1">8</div> <div class="col-1">9</div> <div class="col-1">10</div> <div class="col-1">11</div> <div class="col-1">12</div> </div> <div class="row"> <div class="col-sm-5 col-md-6">.col-sm-5 .col-md-6</div> <div class="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> <div class="row"> <div class="col-sm-6 col-md-5 col-lg-6">.col-sm-6 .col-md-5 .col-lg-6</div> <div class="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> <script ></script> </body> </html>
Responsive effect animation
2.3 Use the .margin utility class to implement offset
The details of this part are in "bootstrap5 The automatic margins in the practical category of "Chinese Manual" are introduced in detail. This part of the content is not very clear in the manual. Let’s use code to demonstrate it and then explain it in detail:
<!doctype html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="keywords" content=""> <meta name="description" content=""> <link href="bootstrap5/bootstrap.min.css" rel="stylesheet"> <style> [class^="col-"] {height: 50px; border: 1px solid #000;} h5{text-align: center;} </style> <title>列的排序</title> </head> <body> <div class="container"> <div class="row row-cols-12"> <div class="col-1">1</div> <div class="col-1">2</div> <div class="col-1">3</div> <div class="col-1">4</div> <div class="col-1">5</div> <div class="col-1">6</div> <div class="col-1">7</div> <div class="col-1">8</div> <div class="col-1">9</div> <div class="col-1">10</div> <div class="col-1">11</div> <div class="col-1">12</div> </div> <h5 id="后面只有自己">后面只有自己</h5> <div class="row"> <div class="col-md-2">.col-md-2</div> <div class="col-md-2 ms-auto">.col-md-2 .ms-auto</div> </div> <h5 id="不需要换行">不需要换行</h5> <div class="row"> <div class="col-md-2">.col-md-2</div> <div class="col-md-2 ms-auto">.col-md-2 .ms-auto</div> <div class="col-md-2">.col-md-2</div> <div class="col-md-2">.col-md-2</div> </div> <h5 id="需要换行">需要换行</h5> <div class="row"> <div class="col-md-2">.col-md-2</div> <div class="col-md-2 ms-auto">.col-md-2 .ms-auto</div> <div class="col-md-2">.col-md-2</div> <div class="col-md-2">.col-md-2</div> <div class="col-md-2">.col-md-2</div> <div class="col-md-2">.col-md-2</div> <div class="col-md-2">.col-md-2</div> <div class="col-md-2">.col-md-2</div> <div class="col-md-2">.col-md-2</div> </div> <h5 id="后面只有自己">后面只有自己</h5> <div class="row"> <div class="col-md-2">.col-md-2</div> <div class="col-md-2 me-auto">.col-md-2 .me-auto</div> </div> <h5 id="不需要换行">不需要换行</h5> <div class="row"> <div class="col-md-2">.col-md-2</div> <div class="col-md-2 me-auto">.col-md-2 .me-auto</div> <div class="col-md-2">.col-md-2</div> <div class="col-md-2">.col-md-2</div> </div> <h5 id="需要换行">需要换行</h5> <div class="row"> <div class="col-md-2">.col-md-2</div> <div class="col-md-2 me-auto">.col-md-2 .me-auto</div> <div class="col-md-2">.col-md-2</div> <div class="col-md-2">.col-md-2</div> <div class="col-md-2">.col-md-2</div> <div class="col-md-2">.col-md-2</div> <div class="col-md-2">.col-md-2</div> <div class="col-md-2">.col-md-2</div> <div class="col-md-2">.col-md-2</div> </div> </div> <script src="bootstrap5/bootstrap.bundle.min.js"></script> </body> </html>
Display effect
##These two parameters are valid when the row is not full (that is, the sum of the number of rasters in the row is less than 12). If the row is exactly full, the parameters are invalid.
- .ms-auto: Right-align itself and the column to its right by adding a left margin.
- .me-auto: Align the column to the right of itself (excluding itself) to the right by adding a right margin.
- It sounds a bit awkward to say, but to put it simply, ms-auto achieves a full line by adding a space to the left. me-auto achieves a full line by adding a space to the right of itself. If the line is exactly full, forget it.
<!doctype html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="keywords" content=""> <meta name="description" content=""> <link href="bootstrap5/bootstrap.min.css" rel="stylesheet"> <style> [class^="col-"] {height: 50px; border: 1px solid #000;} h5{text-align: center;} </style> <title>列的偏移</title> </head> <body> <div class="container"> <h5 id="每个栅格是-的时候">每个栅格是5的时候</h5> <div class="row"> <div class="col-md-5">.col-md-5</div> <div class="col-md-5 ms-auto">.col-md-5 .ms-auto</div> <div class="col-md-5 ms-auto">.col-md-5 .ms-auto</div> <div class="col-md-5">.col-md-5</div> <div class="col-md-5 me-auto">.col-md-5 me-auto</div> <div class="col-md-5">.col-md-5</div> <div class="col-md-5">.col-md-5</div> <div class="col-md-5 me-auto">.col-md-5 me-auto</div> </div> </div> <script src="bootstrap5/bootstrap.bundle.min.js"></script> </body> </html>Display effect
3 Independent column class
.col-*
classes can also be used outside of .row to give elements a specific width. Padding is ignored when a column class is used as a non-direct child of a row. I will not demonstrate this part of the content. I will directly transfer the content of the manual here. Friends who are interested can try it more.<div> .col-3: width of 25% </div> <div> .col-sm-9: width of 75% above sm breakpoint </div>
这些类可以与实用程序一起使用来创建响应的浮动图像。如果文本较短,请确保将内容包装在.clearfix包装器中以清除浮动。
<div> <img class="col-md-6 float-md-end mb-3 ms-md-3 lazy" src="/static/imghwm/default1.png" data-src="..." alt="A brief discussion on how to sort and offset columns in Bootstrap grid layout" > <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>
更多关于bootstrap的相关知识,可访问:bootstrap基础教程!!
The above is the detailed content of A brief discussion on how to sort and offset columns in Bootstrap grid layout. For more information, please follow other related articles on the PHP Chinese website!

React and Bootstrap are ideal combinations. 1) Use Bootstrap's CSS classes and JavaScript components, 2) integrate through React-Bootstrap or reactstrap, 3) load and optimize rendering performance on demand, and build an efficient and beautiful user interface.

Bootstrap is an open source front-end framework for creating modern, responsive, and user-friendly websites. 1) It provides grid systems and predefined styles to simplify layout and development. 2) Mobile-first design ensures compatibility and performance. 3) Through custom styles and components, the website can be personalized. 4) Performance optimization and best practices include selective loading and responsive images. 5) Common errors such as layout problems and style conflicts can be resolved through debugging techniques.

Bootstrap is an open source front-end framework developed by Twitter, suitable for building responsive websites quickly. 1) Its grid system is based on a 12-column structure, allowing for the creation of flexible layouts. 2) Responsive design function enables the website to adapt to different devices. 3) The basic usage includes building a navigation bar, and the advanced usage involves card components. 4) Common errors such as misuse of grid systems can be avoided by correctly setting the column width. 5) Performance optimization includes loading only necessary components, using CDN and file compression. 6) Best practices emphasize tidy code, custom styles and responsive design.

The reason for combining Bootstrap and React is their complementarity: 1. Bootstrap provides predefined styles and components to simplify UI design; 2. React improves efficiency and performance through component development and virtual DOM. Use it in conjunction to enjoy fast UI construction and complex interaction management.

Bootstrap is an open source front-end framework based on HTML, CSS and JavaScript, designed to help developers quickly build responsive websites. Its design philosophy is "mobile first", providing a wealth of predefined components and tools, such as grid systems, buttons, forms, navigation bars, etc., simplifying the front-end development process, improving development efficiency, and ensuring the responsiveness and consistency of the website. Using Bootstrap can start with a simple page and gradually add advanced components such as cards and modal boxes. Best practices for optimizing performance include customizing Bootstrap, using CDNs, and avoiding overuse of class names.

React and Bootstrap can be seamlessly integrated to enhance user interface design. 1) Install dependency package: npminstallbootstrapreact-bootstrap. 2) Import the CSS file: import'bootstrap/dist/css/bootstrap.min.css'. 3) Use Bootstrap components such as buttons and navigation bars. With this combination, developers can leverage React's flexibility and Bootstrap's style library to create a beautiful and efficient user interface.

The steps to integrate Bootstrap into a React project include: 1. Install the Bootstrap package, 2. Import the CSS file, 3. Use Bootstrap class name to style elements, 4. Use React-Bootstrap or reactstrap library to use Bootstrap's JavaScript components. This integration utilizes React's componentization and Bootstrap's style system to achieve efficient UI development.

Bootstrapisapowerfulframeworkthatsimplifiescreatingresponsive,mobile-firstwebsites.Itoffers:1)agridsystemforadaptablelayouts,2)pre-styledelementslikebuttonsandforms,and3)JavaScriptcomponentssuchascarouselsforenhancedinteractivity.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
