Summary of bootstrap learning experience-css style design sharing

Summary of bootstrap learning experience-css style design sharing

Due to the needs of the project, I plan to study the bootstrap framework carefully. I have known a little about it before. The framework is not difficult overall, but there are still many things involved. If I want to master it proficiently, I still need to practice more.

1: What is bootstrap?

What is bs? It is a standardized framework tool for building front-end pages. The css.js style has been written and you just need to use it.

How to use bs? The effect is mainly increased by using different classes, each class has different corresponding functions.

Benefits of bs: increased development efficiency, more beautiful page design, and support for responsive development.

2: CSS style design

1: Based on Html document

Bootstrap references some HTML elements, so the header needs to be written as shown below.

JavaScript CodeCopy content to clipboard
  1. <!DOCTYPE html> ---Contains the HTML5 document declaration, all browsers open the standard mode
  2. <html>
  3. <head>
  4. <meta charset= "utf-8" >
  5. <meta http-equiv= "X-UA-Compatible" content= "IE=edge" >
  6. <meta name= "viewport" content= "width=device-width, initial-scale=1" >
  7. <!-- The above 3 meta tags *must* be placed first, and any other content *must* follow them! Ensure responsive layout -->
  8. <title>Bootstrap</title>
  9. <!-- New Bootstrap core CSS file -->
  10. <link rel= "stylesheet" href= "//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" >
  11.   
  12. <!-- Optional Bootstrap theme file (usually not required) -->
  13. <link rel= "stylesheet" href= "//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" >
  14.   
  15. <!-- jQuery file. Be sure to import before bootstrap.min.js -->
  16. <script src= "//cdn.bootcss.com/jquery/1.11.3/jquery.min.js" ></script>
  17.   
  18. <!-- Latest Bootstrap core JavaScript file -->
  19. <script src= "//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js" ></script>
  20. </head>
  21. <body>
  22. <h1>Hello, world!</h1>
  23. </body>
  24. </html>

2: Grid system layout

Lay out the content by setting rows and columns. Bootstrap sets the page to 12 columns. Layout can be done by changing the number of columns, for example, to set three columns of equal width:

JavaScript CodeCopy content to clipboard
  1. <!DOCTYPE html>
  2. <html lang= "zh-CN" >
  3. <head>
  4. <meta charset= "utf-8" >
  5. <meta http-equiv= "X-UA-Compatible" content= "IE=edge" >
  6. <meta name= "viewport" content= "width=device-width, initial-scale=1" >
  7. <!-- The above 3 meta tags *must* be placed first, and any other content *must* follow them! -->
  8. <title></title>
  9. <link href= "css/bootstrap.css" rel= "stylesheet" >
  10. <link href= "css/bootstrap.min.css" rel= "stylesheet" >
  11. <script src= "http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js" ></script>
  12. <script src= "http://cdn.bootcss.com/bootstrap/3.3.4/js/bootstrap.min.js" ></script>
  13. </head>
  14. <body>
  15. <!-- Set fence layout -->
  16. <div class = "container" ><!--or container-fluid-->
  17. <div class = "row" > -- col-xs-4 : refers to small devices less than 768px
  18. <div class = "col-xs-4" >11</div> -- col-sm-4: refers to devices >=768px
  19. <div class = "col-xs-4" >22</div> -- col-md-4: refers to devices >=992px
  20. <div class = "col-xs-4" >33</div> -- col-lg-4: value 1200px device
  21. </div>
  22. <div class = "row" >
  23. <div class = "col-md-4" >11</div>
  24. <div class = "col-md-4" >22</div>
  25. <div class = "col-md-4" >33</div>
  26. </div>
  27. <div class = "row" >
  28. <div class = "col-sm-4" >11</div>
  29. <div class = "col-sm-4" >22</div>
  30. <div class = "col-sm-4" >33</div>
  31. </div>
  32. <div class = "row" >
  33. <div class = "col-lg-4" >11</div>
  34. <div class = "col-lg-4" >22</div>
  35. <div class = "col-lg-4" >33</div>
  36. </div>
  37.   
  38. </div>
  39. </body>
  40. </html>

There are four ways to write CSS grid formats, which are mainly used for resolutions of different devices.

2: Shift columns

Use offset to translate. The number of columns to shift

XML/HTML CodeCopy content to clipboard
  1. < div    class = "container" > <!--or container-fluid-->   
  2.          < div    class = "row" >   
  3.                       < div    class = "col-xs-4" > 11 </ div >   
  4.                       < div    class = "col-xs-4" > 22 </ div >   
  5.                       < div    class = "col-xs-offset-2 col-xs-4" > 33 </ div > --- means 33 is shifted two columns to the right
  6.           </ div >   
  7.             < div    class = "row" >   
  8.                       < div    class = "col-md-4" > 11 </ div >   
  9.                       < div    class = "col-md-4 col-md-offset-2" > 22 </ div >   
  10.                       < div    class = "col-md-4" > 33 </ div >   
  11.           </ div >     
  12.           < div   class = "row" >   
  13.                  < div   class = "col-md-4" > 11 </ div >   
  14.                  < div   class = "col-md-4 col-md-offset-2" > 22 </ div >     
  15.                  < div   class = "col-md-4" > 33 </ div >     
  16.          </ div >             
  17. </ div >   
  18. <!-- Shift columns -->   

The effect is as follows:

Since 33 is shifted two columns, it cannot meet the requirement of occupying 4 columns, so it is squeezed to the next row and starts to occupy 4 columns. Simply put, it is equivalent to moving the entire div block to the right.

3: Nested columns

That is, nest columns inside grid columns. Let’s compare.

XML/HTML CodeCopy content to clipboard
  1. < div    class = "container" > <!--or container-fluid-->   
  2.          < div    class = "row" >   
  3.                     < div    class = "col-xs-8" >   
  4.                           < div    class = "col-xs-2" > 11 </ div >   
  5.                           < div    class = "col-xs-4" > 22 </ div >   
  6.                           < div    class = "col-xs-2" > 33 </ div >   
  7.                      </ div >   
  8.           </ div >   
  9.             < div    class = "row" >       
  10.                           < div    class = "col-xs-8" > 11 </ div >   
  11.           </ div >   
  12.             < div    class = "row" >       
  13.                         < div    class = "col-xs-4" > 11 </ div >   
  14.                           < div    class = "col-xs-4" > 22 </ div >   
  15.                           < div    class = "col-xs-4" > 33 </ div >   
  16.           </ div >      
  17.           
  18. </ div >   

The effect is as follows:

 

Did you find any problems? Why is the above not evenly distributed 8?
 Reason: Let’s take a look at the debug console
 We found that padding-left and padding-right are both 15px. This is because the padding between columns is affected. So why is there no impact on the second div? Let's explore the principle of the fence grid.

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

2: Create gutters between columns by setting the padding property for the column. By setting a negative margin for the .row element, the padding set for the .container element is offset.
This indirectly offsets the padding for the "column" contained in the "row".
Note: At this point row has offset the padding of the column, so there is no padding value.
4: Column sorting

Mainly using col-xs-push-* col-xs-pull-* (* represents numbers 0-11). How to understand these two classes? Push means pushing, and pull means pulling.
XML/HTML CodeCopy content to clipboard
  1. < div   class = "row" >            
  2.                      < div   class = "col-xs-4" > 21 </ div >   
  3.                      < div   class = "col-xs-8" > 24 </ div >             
  4.       </ div >   
  5.         < div   class = "row" >   
  6.                 
  7.                      < div   class = "col-xs-4 col-xs-push-8" > 21 </ div >   
  8.                      < div   class = "col-xs-4 col-xs-pull-4" > 24 </ div >     
  9.              
  10.       </ div >   
The effect diagram is as follows:
 <div class="col-xs-4 col-xs-push-8">21</div>---recorded as div1
<div class="col-xs-8 col-xs-pull-4">24</div>---remembered as div2, which can be understood as swapping the positions of the two. Div1 needs to be pushed 8 columns to the right, and div2 needs to be pulled 4 columns to the left.

Three: Fluid Grid Layout
1: Use percentages instead of pixels for column widths
2: Change the row class to row-fluid
3: Other basic functions are the same as the fixed layout above, and support responsiveness.
4: When dividing a column equally, since the flow layout uses percentages, it should be calculated according to 6.
XML/HTML CodeCopy content to clipboard
  1. //Note the following situation, when 8 columns are divided equally, it is not set to two 4s, but two 6s, because the bootstrap grid is distributed in 12 columns.
  2.            < div   class = "row" >   
  3.               < div   class = "col-xs-8" >   
  4.                      < div   class = "col-xs-6" > 2 </ div >   
  5.                      < div   class = "col-xs-6" > 2 </ div >   
  6.                    
  7.           </ div >   
  8.       </ div >   

Four: Responsive Design

Simply put, it supports adaptive response to the resolutions (960PX, 1366PX, 978PX, etc.) of different devices (mobile phones, PCs).

XML/HTML CodeCopy content to clipboard
  1. < div   class = "row" >      
  2.                      
  3.                          < div   class = "col-xs-6 col-md-12" > 21 </ div >      
  4.                          < div   class = "col-xs-6 col-md-12" > 24 </ div >        
  5.                      
  6.            </ div >     
When the device is smaller than 768px, the effect is as follows:

When the device is >= 992px. The effect is as follows:

The above two types represent different resolutions. col-md-12 means that each column occupies one row, that is, 12 columns.

The above summary of bootstrap learning experience - CSS style design sharing is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

<<:  Solve the problem that Navicat cannot connect to the MySQL server in the Centos system in VMware

>>:  Database issues and pitfalls in connecting to cloud servers with Navicat Premium15

Recommend

MySQL 5.7.17 winx64 installation and configuration tutorial

Today I installed the MySQL database on my comput...

CSS layout tutorial: How to achieve vertical centering

Preface I have been summarizing my front-end know...

How to unify the character set on an existing mysql database

Preface In the database, some data tables and dat...

MySQL 5.6 root password modification tutorial

1. After installing MySQL 5.6, it cannot be enabl...

Steps to deploy Docker project in IDEA

Now most projects have begun to be deployed on Do...

Example of how to change the domestic source in Ubuntu 18.04

Ubuntu's own source is from China, so the dow...

Solutions to invalid is Null segment judgment and IFNULL() failure in MySql

MySql Null field judgment and IFNULL failure proc...

9 great JavaScript framework scripts for drawing charts on the web

9 great JavaScript framework scripts for drawing ...

Detailed explanation of Vue's seven value transfer methods

1. From father to son Define the props field in t...

How to preview pdf file using pdfjs in vue

Table of contents Preface think Library directory...

How to add file prefixes in batches in Linux

You need to add "gt_" in front of the f...

Vue realizes price calendar effect

This article example shares the specific code of ...

Detailed explanation of the use of Arguments object in JavaScript

Table of contents Preface Basic Concepts of Argum...

Simple encapsulation of axios and example code for use

Preface Recently, when I was building a project, ...