search

bootstrap why 12 raster

Grid system introduction

Bootstrap provides a responsive, mobile-first fluid grid The system, as the screen or viewport size increases, will automatically be divided into up to 12 columns. It contains easy-to-use predefined classes, as well as powerful mixins for generating more semantic layouts.

The grid system creates the layout of the page through a series of combinations of rows and columns. The set content can be placed in the created layout.

The implementation principle of the grid system

The implementation principle of the grid system is very simple, just by defining the size of the container and dividing it equally into 12 Then adjust the inner and outer margins, and finally combine it with media queries to create a powerful responsive grid system.

The main working principle of the grid system:

➣ A row of data (row) must be contained in .container (fixed width) or .container -fluid (100% width) to give it proper alignment and padding.

➣ Create a group of "columns" in the horizontal direction through "rows".

➣ Your specific content should be placed within "column", and only "column" can be a direct child element of row.

➣ There are a lot of built-in styles. You can use styles (i.e. predefined classes) such as .row and .col-xs-4 (four columns wide) to quickly create a grid layout. In the Bootstrap source code The defined mixin can also be used to create semantic layouts.

➣ By setting the padding attribute for "column", the gap between columns (gutter) is created. By setting the padding attribute for "column". The .row element sets a negative margin to offset the padding set for the .container element, which indirectly offsets the padding for the "column" contained in the "row".

➣ Columns in a raster system represent the range they span by specifying a value from 1 to 12. For example, three equal-width columns can be created using three .col-xs-4.

➣ If the "column" contained in a "row" is greater than 12, the elements where the extra "column" is located will be arranged as a whole in another row.

➣ Grid classes apply to devices with screen widths greater than or equal to the breakpoint size, and grid classes are overridden for small screen devices. Therefore, applying any .col-md-* raster classes on an element will apply with devices whose screen width is greater than or equal to the breakpoint size, and the grid class is overridden for small screen devices. Therefore, any .col-lg-* applied on an element does not exist and also affects large screen devices.

Grid system layout container

Bootstrap needs to wrap a .container container for page content and grid system. We provide two classes for this purpose. Note , due to attributes such as padding, these two container classes cannot be nested in each other.

.container class is used for containers with fixed width and supporting responsive layout

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

.container The -fluid class is used for containers with 100% width and occupying the entire viewport

<div class="container-fluid">
  ...
</div>

Using the grid system

The use of the grid system is actually Various combinations of columns. There are four features in basic usage, namely column combination, column offset, column nesting and column sorting. Since different screen sizes use different styles, we take the medium screen (md) as an example Introduction, the usage of other screens is similar.

1. Column combination

Column combination is to merge columns by changing the numbers, similar to colspan in the table. The implementation of column combination is simple and only involves two CSS properties: left float and percentage.

Note: When using the grid system, just remember that the total number of cells in each row is 12, and you can combine them freely according to the actual project.

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

bootstrap why 12 raster

Related recommendations: "bootstrap Getting Started Tutorial"

2. Column offset

Sometimes we don't want two adjacent columns to be next to each other. In this case, we can use the column offset function of the grid system to achieve this without having to define a margin value. For medium screens, you can use styles of the form .col-md-offset-* to offset columns to the right.

For example, .col-md-offset-2 means moving the element to the right by two column widths.

    <!--列偏移-->
    <div class="container">
            <div class="row">
                <div class="col-md-4">.col-md-4</div>
                <div class="col-md-4 col-md-offset-4">.col-md-4 .col-md-offset-4</div>
            </div>
            <div class="row">
                <div class="col-md-3 col-md-offset-3">.col-md-3 .col-md-offset-3</div>
                <div class="col-md-3 col-md-offset-3">.col-md-3 .col-md-offset-3</div>
            </div>
            <div class="row">
                <div class="col-md-6 col-md-offset-3">.col-md-6 .col-md-offset-3</div>
            </div>
    </div>

bootstrap why 12 raster

3. Column nesting

栅格系统也支持列嵌套,即在一个列里再声明一个或多个行(row),但是要注意,内部所嵌套的 row 的宽度为 100% 时,就是当前外部列的宽度。被嵌套的行(row)所包含的列(column)的个数不能超过12。

        <!--列嵌套-->
        <div class="container">
            <div class="row">
                <div class="col-md-8">
                    Level 1:col-md-8
                    <!--在第一行里又添加一行-->
                    <div class="row">
                        <div class="col-md-6">Level 2:col-md-6</div>
                        <div class="col-md-6">Level 2:col-md-6</div>
                    </div>
                    <!--在第一行里又添加一行-->
                    <div class="row">
                        <div class="col-md-3"> Level 3:col-md-3 </div>
                        <div class="col-md-6"> Level 3:col-md-6 </div>
                    </div>
                </div>
                <div class="col-md-4">Level 1:col-md-4</div>
            </div>
        </div>

bootstrap why 12 raster

说明:可以看到,在第一个列(col-md-8)里面,嵌套了一个新行(row),然后在新行里,又放置了两个等宽的(col-md-6)列,并且两个 col-md-6 加起来是12,但是总宽度和外面的 col-md-8 列的宽度一样,也就是说在  row 里的列宽度是按照百分比分配的。在任何一个嵌套列里,不管宽度是多少,都可以再进行 12 等分,并可以进一步组合。

4、列排序

列排序就是改变列的方向,也就是改变左右浮动,并设置浮动的距离。在栅格系统里,可以通过 .col-md-push-* 和 .col-md-pull-* 来实现这一目的。

     <!--列排序-->
        <div class="container">
            <div class="row">
              <div class="col-md-9 col-md-push-3">.col-md-9 .col-md-push-3</div>
              <div class="col-md-3 col-md-pull-9">.col-md-3 .col-md-pull-9</div>
          </div>
        </div>

bootstrap why 12 raster

说明:默认情况下,col-md-9 在左边,col-md-3 在右边,如果要互换位置,需要将 col-md-9 列向右移动三个列的距离,也就是推三个列的 offset,样式用 col-md-push-3;而 col-md-3 需要向左移动,也就是拉九个 offset,样式用 col-md-pull-9。

响应式栅格

我们都知道,Bootstrap 可以制作响应式页面。它能为不同屏幕尺寸提供不同栅格样式。在前面的例子中,我们一直都在使用中等屏幕(md),既然是响应式页面,当然还应该包括超小屏幕(xs)、小型屏幕(sm)、大屏幕(lg)等。

Bootstrap 栅格参数

说明:通过下表可以详细查看 Bootstrap 的栅格系统是如何在多种屏幕设备上工作的。

bootstrap why 12 raster

The above is the detailed content of bootstrap why 12 raster. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
React and Bootstrap: The Ideal Combination?React and Bootstrap: The Ideal Combination?May 01, 2025 am 12:01 AM

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.

Using Bootstrap: Creating Modern and Mobile-First WebsitesUsing Bootstrap: Creating Modern and Mobile-First WebsitesApr 30, 2025 am 12:08 AM

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 and Web Design: Best Practices and TechniquesBootstrap and Web Design: Best Practices and TechniquesApr 29, 2025 am 12:15 AM

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.

Bootstrap and React: Combining Frameworks for Web DevelopmentBootstrap and React: Combining Frameworks for Web DevelopmentApr 28, 2025 am 12:08 AM

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.

From Zero to Bootstrap: Getting Started QuicklyFrom Zero to Bootstrap: Getting Started QuicklyApr 27, 2025 am 12:07 AM

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: Enhancing User Interface DesignReact and Bootstrap: Enhancing User Interface DesignApr 26, 2025 am 12:18 AM

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.

Integrating Bootstrap into React: A Practical GuideIntegrating Bootstrap into React: A Practical GuideApr 25, 2025 am 12:04 AM

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.

What is Bootstrap Used For? A Practical ExplanationWhat is Bootstrap Used For? A Practical ExplanationApr 24, 2025 am 12:16 AM

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

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 Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

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

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

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.