search
HomeWeb Front-endBootstrap TutorialTalk about the grid system in Bootstrap

Talk about the grid system in Bootstrap

Jan 26, 2021 pm 06:51 PM
bootstrapgrid system

This article will talk to you about 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.

Talk about the grid system in Bootstrap

Related recommendations: "bootstrap Basic Tutorial"

The grid system in the bootstrap framework divides the container into equal parts 12 copies. When using, 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 ( padding)

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

2. You can add columns (.column) in rows (.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 spacing between columns by setting padding, and then offset it by setting negative margins for the first column and the last stack. The impact of padding

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

container (.container), for different browser resolutions, its width is 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 30px of the middle 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 row 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 There is no gap between it and the container (.container)

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

Basic usage

Because the bootstrap framework is different Different grid styles are used for screen sizes. The following takes the medium screen (970px) as an example.

1. Column combination

Column combination is to change the number to merge the columns (the total number of columns cannot exceed 12), which is somewhat similar to the colspan of the table Properties; the column combination method only involves two characteristics: floating 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:

Talk about the grid system in Bootstrap

Ensure all columns are left floated

.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 the width of each column combination

.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%;
  }

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 by 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:

Talk about the grid system in Bootstrap

Implementation principle:

Using one-twelfth of the 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-* to right-offset a column, ensure that the total number of columns and offset columns does not exceed 12, otherwise the columns will be broken. Display

Column sorting

Column 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. col-md-push-* and col-md-pull-*

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

效果如下:

Talk about the grid system in Bootstrap

col-md-4居左,col-md-8居右,如果要互换位置,就需要将col-md-4向右移动8个列的距离,也就是添加类名.col-md-push-8;同时需要将col-md-8向左移动4个列的距离,也就是添加类名.col-md-pull-4

bootstrap仅通过设置left和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;
  }

列嵌套

列嵌套可以在一个列中添加一个或做个行(row)容器,然后在这个行容器中插入列,在列容器中的行容器(row),宽度为100%时,就是当前外部列的宽度

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

Talk about the grid system in Bootstrap

更多编程相关知识,请访问:编程视频!!

The above is the detailed content of Talk about the grid system in Bootstrap. 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
Understanding the Bootstrap Grid System for Responsive Web DesignUnderstanding the Bootstrap Grid System for Responsive Web DesignMay 14, 2025 am 12:07 AM

Bootstrap'sgridsystemiseffectiveduetoits12-columnlayoutandresponsiveclasses,allowingforflexibleandmaintainabledesigns.Toleverageit:1)Userowsandcolumnswithclasseslikecol-md,col-sm,andcol-lgfordifferentscreensizes.2)Simplifylayoutsbyavoidingexcessivene

Bootstrap Grid System: A Comprehensive Guide to Responsive LayoutsBootstrap Grid System: A Comprehensive Guide to Responsive LayoutsMay 13, 2025 pm 04:17 PM

BootstrapGridSystemisessentialforcreatingresponsivelayouts.1)Itusescontainers,rows,andcolumnsbasedona12-columnlayout.2)CSSflexboxandmediaqueriesensureflexibilityacrossscreensizes.3)Classeslikecol-xs,col-sm,col-md,andcol-lgcontrollayoutchanges.4)Avoid

Bootstrap: Applications and Advantages ExplainedBootstrap: Applications and Advantages ExplainedMay 10, 2025 am 12:18 AM

Bootstrap is a front-end framework for quickly building responsive websites. Its advantages include: 1. Rapid development: leverage predefined styles and components. 2. Consistency: Provide a unified design style. 3. Responsive design: The built-in grid system is adapted to various devices. Bootstrap simplifies the web development process through CSS classes and JavaScript plug-ins.

Bootstrap: Simplifying Responsive Web DevelopmentBootstrap: Simplifying Responsive Web DevelopmentMay 09, 2025 am 12:13 AM

Bootstrap simplifies the development process mainly through its raster system, predefined components and JavaScript plug-ins. 1. The grid system allows for flexible layout, 2. Predefined components such as buttons and navigation bars simplify style design, 3. JavaScript plug-in enhances interactive functions and improves development efficiency.

Bootstrap: The Key to Responsive Web DesignBootstrap: The Key to Responsive Web DesignMay 08, 2025 am 12:24 AM

Bootstrap is an open source front-end framework developed by Twitter, providing rich CSS and JavaScript components, simplifying the construction of responsive websites. 1) Its grid system is based on a 12-column layout, and the display of elements under different screen sizes is controlled through class names. 2) The component library includes buttons, navigation bars, etc., which are easy to customize and use. 3) The working principle depends on CSS and JavaScript files, and you need to pay attention to handling dependencies and style conflicts. 4) The usage examples show basic and advanced usage, emphasizing the importance of custom functionality. 5) Common errors include grid system calculation errors and style coverage, which require debugging using developer tools. 6) Performance optimization recommendations only introduce necessary components and customize samples using preprocessors

Bootstrap: A Powerful Framework for Web DesignBootstrap: A Powerful Framework for Web DesignMay 07, 2025 am 12:05 AM

Bootstrap is an open source front-end framework developed by the Twitter team to simplify and speed up the web development process. 1.Bootstrap is based on HTML, CSS and JavaScript, and provides a wealth of components and tools for creating modern user interfaces. 2. Its core lies in responsive design, implementing various layouts and styles through predefined classes and components. 3.Bootstrap provides predefined UI components, such as navigation bars, buttons, forms, etc., which are easy to use and adjust. 4. Examples of usage include creating a simple navigation bar and advanced collapsible sidebar. 5. Common errors include version conflicts, CSS overwrites and JavaScript errors, which can be used through the version management tool.

The Power of Bootstrap in React: A Detailed LookThe Power of Bootstrap in React: A Detailed LookMay 06, 2025 am 12:06 AM

Bootstrap can be integrated in React in two ways: 1) CSS and JavaScript files using Bootstrap; 2) Use the React-Bootstrap library. React-Bootstrap provides encapsulated React components, making using Bootstrap in React more natural and efficient.

Using Bootstrap Components in React: A Step-by-Step TutorialUsing Bootstrap Components in React: A Step-by-Step TutorialMay 05, 2025 am 12:09 AM

There are two ways to use Bootstrap components in React projects: 1) CSS and JavaScript of the original Bootstrap; 2) Use libraries designed specifically for React such as react-bootstrap or reactstrap. 1) Install Bootstrap through npm and introduce its CSS file in the entry file, and then use the Bootstrap class name in the React component. 2) After installing react-bootstrap or reactstrap, directly use the React components it provides. Use these methods to quickly build a responsive UI, but pay attention to style loading and JavaScript

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

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment