Talk about grid layout in css (graphics and text)
(Learning video sharing: css video tutorial)
Grid layout can divide the web page into rows and columns of simple attributes, CSS page layout Technology allows us to pick up elements in a web page and control their position relative to the normal layout flow, surrounding elements, parent containers, or the main viewport/window.
Holy Grail Layout
Holy Grail Layout is a three-column layout with fixed width on both sides and adaptive middle:
css:
* { box-sizing: border-box; } html, body{ width: 100%; height: 100%; margin: 0; } .container{ width:100%; } .container:after{ display: table; content:"."; clear:both; } .container .cl{ float:left; border: 1px solid red; height: 200px; } .main{ width:100%; padding 0 290px 0 320px; background-color: blue; } .sub{ width: 320px; margin-left:-100%; background-color: white; } .extra{ width: 290px; margin-left:-290px; background-color: yellow; } CSS
HTML:
<body> <div class="container"> <div class="cl main"> </div> <div class="cl sub"></div> <div class="cl extra"></div> </div> </body>
The principle of holy grail layout is that when the child element is in a floating state, set a negative margin, and the child element will overlap the brothers above the elements.
So if you want to divide the blue area into three areas again, I believe there are many ways. But can it be achieved through nesting? We can try it:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <meta http-equiv="window-target" content="_top"> <title>Writing to Same Doc</title> <style type="text/css"> * { box-sizing: border-box; } html, body{ width: 100%; height: 100%; margin: 0; } .container{ width:100%; } .container:after{ display: table; content:"."; clear:both; } .container .cl{ float:left; border: 1px solid red; height: 200px; } .main{ width:100%; padding: 0 290px 0 320px; background-color: blue; } .sub{ width: 320px; margin-left:-100%; background-color: white; } .extra{ width: 290px; margin-left:-290px; background-color: yellow; } </style> </head> <body> <div class="container"> <div class="cl main"> <div class="container"> <div class="cl main"></div> <div class="cl sub"></div> <div class="cl extra"></div> </div> </div> <div class="cl sub"></div> <div class="cl extra"></div> </div> </body> </html>
The principle of grid system
Assumption: Flowline The width of is W, the width of column is c, the width of Gutter is g, the width of Margin is m, and the number of grid columns is N
W = c*N g*(N-1) 2m; g The width of is usually twice that of m, so:
W = (c g) * N; record c g as C, we get:
W = C * N;
Most grid systems are variations of this formula.
Bootstrap’s grid system
Let’s take a look at common grid layout designs and design implementations in bootstrap. To properly use grid layout in BootStrap, columns must be placed in rows, and rows must be placed in containers. The container class has two main functions in layout:
Provide width restrictions in different width intervals (responsive breakpoints). When the width changes, take a different width.
Provide a padding to prevent internal content from touching the browser borders.
Padding is used in Bootstrap instead of the margin mentioned above. The size is 15px, as shown in the picture below, and the pink color is the padding size.
Row is a container of columns. The sum of columns in each row must be 12, but we can expand it by nesting. The left and right margins of Row are -15px, which is used to offset the padding in the container, as shown in the blue part of the figure below:
This design of row is mainly for the convenience of nesting. , will be mentioned later.
Colomn is the protagonist of the grid system. The left and right padding of each column is 15px. The negative margin of the row above offsets the padding of the container, so setting padding for each column is to prevent the content from directly touching the border. , and there are 30px card slots (Gutter) between different columns. As shown in the yellow part of the picture below:
Now think about the formula mentioned above: W = C * N;
row mentioned above The negative margin design is mainly for nesting. If you want to nest a column in a column, you must first put the nested column into the row, and put the row into the column as the container, without placing a container. As shown in blue in the figure below, it is the negative margin area of the row placed in the column.
Now put the nested column into the row, as shown in the figure below, the upper column plays the role of container.
For more programming-related knowledge, please visit: Programming Learning! !
The above is the detailed content of Talk about grid layout in css (graphics and text). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

Answer: You can use the date picker component of Bootstrap to view dates in the page. Steps: Introduce the Bootstrap framework. Create a date selector input box in HTML. Bootstrap will automatically add styles to the selector. Use JavaScript to get the selected date.

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.
