Home Web Front-end JS Tutorial Chapter 5: BootStrap Grid System_javascript skills

Chapter 5: BootStrap Grid System_javascript skills

May 16, 2016 pm 03:04 PM

Bootstrap, from Twitter, is currently the most popular front-end framework. Bootstrap is based on HTML, CSS, and JAVASCRIPT. It is simple and flexible, making web development faster.

Learning points:

1. Mobile devices first
2. Layout container
3. Grid system

In this lesson we will mainly learn about Bootstrap’s grid system, which provides a responsive, mobile-first fluid grid system.

1. Mobile first

In the HTML5 project, we made a mobile project. It has a very important meta, which is used to set the same width as the screen and device, whether to run user scaling, and the scaling ratio.

1

2

//分别为:屏幕宽度和设备一致、初始缩放比例、最大缩放比例和禁止用户缩放

<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">

Copy after login

2. Layout container

Bootstrap requires a .container container to wrap the page content and grid system. Due to attributes such as padding, these two container classes cannot be nested in each other.

1

2

3

4

5

6

7

8

//固定宽度

<div class="container">

...

</div>

//100%宽度

<div class="container-fluid">

...

</div>

Copy after login

In the grid system, the browser will automatically allocate up to 12 columns as the screen size increases or decreases. Create a page layout through a series of rows and columns. Here’s how it works:

1. "Row" must be contained in .container (fixed width) or .container-fluid (100% width) in order to give it appropriate alignment and padding.

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

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

4. Predefined classes like .row and .col-xs-4 can be used to quickly create grid layouts.
Mixins defined in the Bootstrap source code can also be used to create semantic layouts.

5. Create a gutter between columns by setting the padding attribute for "column". By setting a negative value for the .row element

margin thus offsets the padding set for the .container element, and indirectly offsets the padding for the "column" contained in the "row".

6. The negative value of margin is why the example below protrudes outward. Contents in grid columns line up.

7. Columns in the grid system represent the range they span by specifying values ​​from 1 to 12. For example, three equal-width columns can be created using three .col-xs-4 s.

8. If a "row" contains more than 12 "columns", the elements of the extra "columns" will be arranged as a whole in another row.

9. The grid class is suitable for devices with a screen width greater than or equal to the dividing point size, and the grid class is overridden for small screen devices. Therefore, applying any .col-md-* raster classes on an element works for devices with screen widths greater than or equal to the breakpoint size, and overrides the raster class for small-screen devices. Therefore, applying any .col-lg-* on the element does not exist and also affects large screen devices.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

//创建一个响应式行

<div class="container">

<div class="row">

...

</div>

</div>

//创建最多 12 列的响应式行

<div class="container">

<div class="row">

<div class="col-md-1 a">1</div>

<div class="col-md-1 a">2</div>

<div class="col-md-1 a">3</div>

<div class="col-md-1 a">4</div>

<div class="col-md-1 a">5</div>

<div class="col-md-1 a">6</div>

<div class="col-md-1 a">7</div>

<div class="col-md-1 a">8</div>

<div class="col-md-1 a">9</div>

<div class="col-md-1 a">10</div>

<div class="col-md-1 a">11</div>

<div class="col-md-1 a">12</div>

</div>

</div>

//为了显示明显的 CSS

.a {

height: 100px;

background-color: #eee;

border: 1px solid #ccc;

}

//总列数都是 12,每列分配多列

<div class="container">

<div class="row">

<div class="col-md-4 a">1-4</div>

<div class="col-md-4 a">5-8</div>

<div class="col-md-4 a">9-12</div>

</div>

<div class="row">

<div class="col-md-8 a">1-8</div>

<div class="col-md-4 a">9-12</div>

</div>

</div>

Copy after login

Raster parameter table

As shown in the picture above, the outermost layer of the grid system distinguishes four browser widths: ultra-small screen (<768px), small screen (>=768px), medium screen (>=992px) and Large screen (>=1200px). The adaptive widths of the inner .container container are: automatic, 750px, 970px and 1170px. Automatic means that if you are on a mobile phone screen, it will occupy one line of display.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

//四种屏幕分类全部激活

<div class="container">

<div class="row">

<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">4</div>

<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">4</div>

<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">4</div>

<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">4</div>

<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">4</div>

<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">4</div>

<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">4</div>

<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">4</div>

<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">4</div>

<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">4</div>

<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">4</div>

<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">4</div>

</div>

</div>

//有时我们可以设置列偏移,让中间保持空隙

<div class="container">

<div class="row">

<div class="col-md-8 a">8</div>

<div class="col-md-3 col-md-offset-1 a">3</div>

</div>

</div>

//也可以嵌套,嵌满也是 12 列

<div class="container">

<div class="row">

<div class="col-md-9 a">

<div class="col-md-8 a">1-8</div>

<div class="col-md-4 a">9-12</div>

</div>

<div class="col-md-3 a">

11-12

</div>

</div>

</div>

//可以把两个列交换位置,push 向左移动,pull 向右移动

<div class="container">

<div class="row">

<div class="col-md-9 col-md-push-3 a">9</div>

<div class="col-md-3 col-md-pull-9 a">3</div>

</div>

</div>

Copy after login

The above is the relevant information for the BootStrap grid system. I hope it will be helpful to everyone!

Statement of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if I encounter garbled code printing for front-end thermal paper receipts? What should I do if I encounter garbled code printing for front-end thermal paper receipts? Apr 04, 2025 pm 02:42 PM

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

Who gets paid more Python or JavaScript? Who gets paid more Python or JavaScript? Apr 04, 2025 am 12:09 AM

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to merge array elements with the same ID into one object using JavaScript? How to merge array elements with the same ID into one object using JavaScript? Apr 04, 2025 pm 05:09 PM

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

The difference in console.log output result: Why are the two calls different? The difference in console.log output result: Why are the two calls different? Apr 04, 2025 pm 05:12 PM

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...

TypeScript for Beginners, Part 2: Basic Data Types TypeScript for Beginners, Part 2: Basic Data Types Mar 19, 2025 am 09:10 AM

Once you have mastered the entry-level TypeScript tutorial, you should be able to write your own code in an IDE that supports TypeScript and compile it into JavaScript. This tutorial will dive into various data types in TypeScript. JavaScript has seven data types: Null, Undefined, Boolean, Number, String, Symbol (introduced by ES6) and Object. TypeScript defines more types on this basis, and this tutorial will cover all of them in detail. Null data type Like JavaScript, null in TypeScript

How to achieve parallax scrolling and element animation effects, like Shiseido's official website?
or:
How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? How to achieve parallax scrolling and element animation effects, like Shiseido's official website? or: How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? Apr 04, 2025 pm 05:36 PM

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

Can PowerPoint run JavaScript? Can PowerPoint run JavaScript? Apr 01, 2025 pm 05:17 PM

JavaScript can be run in PowerPoint, and can be implemented by calling external JavaScript files or embedding HTML files through VBA. 1. To use VBA to call JavaScript files, you need to enable macros and have VBA programming knowledge. 2. Embed HTML files containing JavaScript, which are simple and easy to use but are subject to security restrictions. Advantages include extended functions and flexibility, while disadvantages involve security, compatibility and complexity. In practice, attention should be paid to security, compatibility, performance and user experience.

See all articles