search
HomeWeb Front-endBootstrap TutorialDetailed explanation of the grid system for Bootstrap learning

This article will introduce to you the grid system in Bootstrap. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

Detailed explanation of the grid system for Bootstrap learning

Related recommendations: "bootstrap Tutorial"

The grid system in the bootstrap framework divides the container into 12 equal parts. When using it, you can recompile the LESS/SASS source code according to the actual situation to modify the value of 12. The working principle of the bootstrap framework's grid system:

1. The data row (.row) must be contained in the container (.container) so that it can be given appropriate alignment and padding

<div class="container">
<div class="row"></div>
</div>

2. Columns (.column) can be added to the row (.row), but the sum of the number of columns cannot exceed the total number of equally divided columns (such as: 12)

<div class="container">
<div class="row">
  <div class="col-md-4"></div>
  <div class="col-md-8"></div>
</div>
</div

3. The specific content should be placed Within the column container (.column), and only the column (.column) can be used as a direct child element of the row container (.row)

4. Create columns and columns by setting the padding (padding) spacing between them, and then offset the effect of padding by setting negative margins for the first column and the last stack

With responsive effects in the bootstrap grid system , which comes with four types of browsers (extra small screen, small screen, medium screen and large screen), and its breakpoints are 768px, 992px, 1220px

container (.container), for different Browser resolutions and widths are also different: automatic, 760px, 970px, 1170px;

.container {
  padding-right: 15px;
  padding-left: 15px;
  margin-right: auto;
  margin-left: auto;
  @media (min-width: 768px) {
  .container {
    width: 750px;
  }
  @media (min-width: 992px) {
  .container {
    width: 970px;
  }
  @media (min-width: 1200px) {
  .container {
    width: 1170px;
  }

Row container (.row) divides the row of the container into 12 equal parts, that is, columns. Each column has a padding-left: 15px and a padding-right: 15px; this also causes the padding-left of the first column and the padding-right of the last column to occupy a 30px line of medium width

.col-xs-1, .col-sm-1, .col-md-1, .col-lg-1, .col-xs-2, .col-sm-2, .col-md-2, .col-lg-2, .col-xs-3, .col-sm-3, .col-md-3, .col-lg-3, .col-xs-4, .col-sm-4, .col-md-4, .col-lg-4, .col-xs-5, .col-sm-5, .col-md-5, .col-lg-5, .col-xs-6, .col-sm-6, .col-md-6, .col-lg-6, .col-xs-7, .col-sm-7, .col-md-7, .col-lg-7, .col-xs-8, .col-sm-8, .col-md-8, .col-lg-8, .col-xs-9, .col-sm-9, .col-md-9, .col-lg-9, .col-xs-10, .col-sm-10, .col-md-10, .col-lg-10, .col-xs-11, .col-sm-11, .col-md-11, .col-lg-11, .col-xs-12, .col-sm-12, .col-md-12, .col-lg-12 {
  position: relative;
  min-height: 1px;
  padding-right: 15px;
  padding-left: 15px;
}

The container (.row) defines margin-left and margin-right values ​​of -15px, which are used to offset the left padding of the first column and the right padding of the last column, so that the first and last columns are in line with the container (.container) There is no space between

.row {
  margin-right: -15px;
  margin-left: -15px;
}

Basic usage

Since the bootstrap framework uses different grid styles for different screen sizes, the following is Take the medium screen (970px) as an example.

1. Column combination

Column combination is to change the number to merge columns (the total number of columns cannot exceed 12), which is somewhat similar to the colspan attribute of the table; the column combination method is only Involves two features: Float in width percentage

<div>
           <div>
               <div>col-md-4</div>
               <div>col-md-8</div>
           </div>
           <div>
               <div>col-md-4</div>
               <div>col-md-4</div>
               <div>col-md-4</div>
           </div>
           <div>
               <div>col-md-3</div>
               <div>col-md-6</div>
               <div>col-md-3</div>
           </div>
       </div>

The effect is as follows:

Detailed explanation of the grid system for Bootstrap learning

Ensure that all columns float left

.col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 {
    float: left;
 }

Define each column Combined width

.col-md-12 {
    width: 100%;
  }
  .col-md-11 {
    width: 91.66666667%;
  }
  .col-md-10 {
    width: 83.33333333%;
  }
  .col-md-9 {
    width: 75%;
  }
  .col-md-8 {
    width: 66.66666667%;
  }
  .col-md-7 {
    width: 58.33333333%;
  }
  .col-md-6 {
    width: 50%;
  }
  .col-md-5 {
    width: 41.66666667%;
  }
  .col-md-4 {
    width: 33.33333333%;
  }
  .col-md-3 {
    width: 25%;
  }
  .col-md-2 {
    width: 16.66666667%;
  }
  .col-md-1 {
    width: 8.33333333%;
  }

2, column offset

Sometimes, we don’t want two adjacent columns to be close together, but we don’t want to use margin or Other technical means, this can be achieved using column offset (offset). To use column offset, just add the class name .col-md-offset-* (the asterisk represents the number of column combinations to be offset) on the column element, and the column with this class name will be offset, such as: in the column element Add .col-md-offset-4 to the column to indicate that the column is offset to the right by the width of 4 columns

<div>
           <div>
               <div>1111</div>
               <div>111</div>
               <div>333</div>
           </div>
           <div>
               <div>列偏移</div>
               <div>col-md-2</div>
               <div>col-md-2</div>
           </div>
       </div>

The effect is as follows:

Detailed explanation of the grid system for Bootstrap learning

Implementation principle :

Use one-twelfth margin-left, there are as many margin-lefts as there are offsets

.col-md-offset-12 {
   margin-left: 100%;
}
  .col-md-offset-11 {
    margin-left: 91.66666667%;
  }
  .col-md-offset-10 {
    margin-left: 83.33333333%;
  }
  .col-md-offset-9 {
    margin-left: 75%;
  }
  .col-md-offset-8 {
    margin-left: 66.66666667%;
  }
  .col-md-offset-7 {
    margin-left: 58.33333333%;
  }
  .col-md-offset-6 {
    margin-left: 50%;
  }
  .col-md-offset-5 {
    margin-left: 41.66666667%;
  }
  .col-md-offset-4 {
    margin-left: 33.33333333%;
  }
  .col-md-offset-3 {
    margin-left: 25%;
  }
  .col-md-offset-2 {
    margin-left: 16.66666667%;
  }
  .col-md-offset-1 {
    margin-left: 8.33333333%;
  }
  .col-md-offset-0 {
    margin-left: 0;
  }

It should be noted that when using col-md-offset-* When right-shifting a column, make sure that the total number of columns and offset columns does not exceed 12, otherwise it will cause columns to break and display

4, column sorting

columns Sorting is to change the direction of the column and set the floating distance. In the bootstrap grid system it is done by adding the class name. The effects of col-md-push-* and col-md-pull-*

<div>
       <div>
          <div>col-md-4</div>
          <div>col-md-8</div>
       </div>
   </div>

are as follows:

Detailed explanation of the grid system for Bootstrap learning

col-md-4 is on the left, col-md -8 is on the right. If you want to swap positions, you need to move col-md-4 to the right by 8 columns, that is, add the class name.col-md-push-8; at the same time, you need to move col-md-8 Move 4 columns to the left, that is, add the class name.col-md-pull-4

bootstrap only achieves the positioning effect by setting left and right.

.col-md-pull-12 {
    right: 100%;
  }
  .col-md-pull-11 {
    right: 91.66666667%;
  }
  .col-md-pull-10 {
    right: 83.33333333%;
  }
  .col-md-pull-9 {
    right: 75%;
  }
  .col-md-pull-8 {
    right: 66.66666667%;
  }
  .col-md-pull-7 {
    right: 58.33333333%;
  }
  .col-md-pull-6 {
    right: 50%;
  }
  .col-md-pull-5 {
    right: 41.66666667%;
  }

  .col-md-pull-4 {
    right: 33.33333333%;
  }

  .col-md-pull-3 {
    right: 25%;
  }

  .col-md-pull-2 {
    right: 16.66666667%;
  }
  .col-md-pull-1 {
    right: 8.33333333%;
  }
  .col-md-pull-0 {
    right: 0;
  }

  .col-md-push-12 {
    left: 100%;
  }
  .col-md-push-11 {
    left: 91.66666667%;
  }
  .col-md-push-10 {
    left: 83.33333333%;
  }
  .col-md-push-9 {
    left: 75%;
  }
  .col-md-push-8 {
    left: 66.66666667%;
  }
  .col-md-push-7 {
    left: 58.33333333%;
  }
  .col-md-push-6 {
    left: 50%;
  }
  .col-md-push-5 {
    left: 41.66666667%;
  }
  .col-md-push-4 {
    left: 33.33333333%;
  }
  .col-md-push-3 {
    left: 25%;
  }
  .col-md-push-2 {
    left: 16.66666667%;
  }
  .col-md-push-1 {
    left: 8.33333333%;
  }
  .col-md-push-0 {
    left: 0;
  }

5. Column nesting

Column nesting can add a column or make a row (row) container, and then insert it in this row container Column, in the row container (row) in the column container, when the width is 100%, it is the width of the current outer column

<div>
       <div>
           <div>
               我在里面嵌套了一个网格
               <div>
                   <div>col-md-6</div>
                   <div>col-md-6</div>
               </div>
           </div>
           <div>col-md-4</div>
       </div>
       <div>
           <div>col-md-4</div>
           <div>
               我在里面嵌套了一个网格
               <div>
                   <div>col-md-4</div>
                   <div>col-md-4</div>
                   <div>col-md-4</div>
               </div>
           </div>
       </div>
   </div>

Detailed explanation of the grid system for Bootstrap learning

更多编程相关知识,请访问:编程入门!!

The above is the detailed content of Detailed explanation of the grid system for Bootstrap learning. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:博客园. If there is any infringement, please contact admin@php.cn delete
10款好看又实用的Bootstrap后台管理系统模板(快来下载)10款好看又实用的Bootstrap后台管理系统模板(快来下载)Aug 06, 2021 pm 01:55 PM

一个好的网站,不能只看外表,网站后台同样很重要。本篇文章给大家分享10款好看又实用的Bootstrap后台管理系统模板,可以帮助大家快速建立强大有美观的网站后台,欢迎下载使用!如果想要获取更多后端模板,请关注php中文网后端模板栏目!

bootstrap与jquery是什么关系bootstrap与jquery是什么关系Aug 01, 2022 pm 06:02 PM

bootstrap与jquery的关系是:bootstrap是基于jquery结合了其他技术的前端框架。bootstrap用于快速开发Web应用程序和网站,jquery是一个兼容多浏览器的javascript库,bootstrap是基于HTML、CSS、JAVASCRIPT的。

7款实用响应式Bootstrap电商源码模板(快来下载)7款实用响应式Bootstrap电商源码模板(快来下载)Aug 31, 2021 pm 02:13 PM

好看又实用的Bootstrap电商源码模板可以提高建站效率,下面本文给大家分享7款实用响应式Bootstrap电商源码,均可免费下载,欢迎大家使用!更多电商源码模板,请关注php中文网电商源码​栏目!

8款Bootstrap企业公司网站模板(源码免费下载)8款Bootstrap企业公司网站模板(源码免费下载)Aug 24, 2021 pm 04:35 PM

好看又实用的企业公司网站模板可以提高您的建站效率,下面PHP中文网为大家分享8款Bootstrap企业公司网站模板,均可免费下载,欢迎大家使用!更多企业站源码模板,请关注php中文网企业站源码栏目!

bootstrap中sm是什么意思bootstrap中sm是什么意思May 06, 2022 pm 06:35 PM

在bootstrap中,sm是“小”的意思,是small的缩写;sm常用于表示栅格类“.col-sm-*”,是小屏幕设备类的意思,表示显示大小大于等于768px并且小于992px的屏幕设备,类似平板设备。

bootstrap默认字体大小是多少bootstrap默认字体大小是多少Aug 22, 2022 pm 04:34 PM

bootstrap默认字体大小是“14px”;Bootstrap是一个基于HTML、CSS、JavaScript的开源框架,用于快速构建基于PC端和移动端设备的响应式web页面,并且默认的行高为“20px”,p元素行高为“10px”。

bootstrap modal 如何关闭bootstrap modal 如何关闭Dec 07, 2020 am 09:41 AM

bootstrap modal关闭的方法:1、连接好bootstrap的插件;2、给按钮绑定模态框事件;3、通过“ $('#myModal').modal('hide');”方法手动关闭模态框即可。

bootstrap是免费的吗bootstrap是免费的吗Jun 21, 2022 pm 05:31 PM

bootstrap是免费的;bootstrap是美国Twitter公司的设计师“Mark Otto”和“Jacob Thornton”合作基于HTML、CSS、JavaScript 开发的简洁、直观、强悍的前端开发框架,开发完成后在2011年8月就在GitHub上发布了,并且开源免费。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

mPDF

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),

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.