Preface When making a page, we often encounter content related to page layout, and we are often asked about it during interviews. So today I will summarize the content about page layout. Question: How to implement a three-column layout (fixed height, left-center-right structure) Assuming the height is known, please write a three-column layout with the left and right widths both being 300px and the middle being adaptive. After reading the above topic, experienced people may find it very simple. Think about it carefully, if we were to write it, how many solutions could we come up with? Generally, there are two types that come to mind, float and position positioning. In fact, in addition to these two, there are 3 more types that can be written. Let me introduce them one by one: Solution 1 (float) <section class='layout float'> <style> .layout.float .left-right-center{ height: 100px; } .layout.float .left{ float: left; width: 300px; background-color: red; } .layout.float .right{ float: right; width: 300px; background-color: blue; } .layout.float .center{ background-color: yellow; } </style> <article class="left-right-center"> <div class="left"></div> <div class="right"></div> <div class="center">I am the adaptive element in the middle--floating</div> </article> </section>
Solution 2 (absolute positioning) <section class="layout absolute"> <style> .layout.absolute .left-center-right div{ position: absolute; height: 100px; } .layout.absolute .left{ left: 0; width: 300px; background-color: red; } .layout.absolute .center{ left: 300px; right: 300px; background-color: yellow; } .layout.absolute .right{ right: 0; width: 300px; background-color: blue; } </style> <article class="left-center-right"> <div class="left"></div> <div class="center"> I am the adaptive element in the middle - absolute positioning</div> <div class="right"></div> </article> </section>
Solution 3 (flex layout) <section class="layout flex"> <style> .layout.flex .left-center-right{ display: flex; height: 100px; } .layout.flex .left{ width: 300px; background-color: red; } .layout.flex .center{ flex: 1; background-color: yellow; } .layout.flex .right{ width: 300px; background-color: blue; } </style> <article class="left-center-right"> <div class="left"></div> <div class="center"> I am the adaptive element in the middle - flex layout</div> <div class="right"></div> </article> </section>
Solution 4 (table layout) <section class="layout table"> <style> .layout.table .left-center-right{ display: table; height: 100px; width: 100%; } .layout.table .left{ display: table-cell; width: 300px; background-color: red; } .layout.table .center{ display: table-cell; background-color: yellow; } .layout.table .right{ display: table-cell; width: 300px; background-color: blue; } </style> <article class="left-center-right"> <div class="left"></div> <div class="center"> I am the adaptive element in the middle - table </div> <div class="right"></div> </article> </section>
Option 5 (Grid Layout) <section class="layout grid"> <style> .layout.grid .left-center-right{ display: grid; width: 100%; grid-template-rows: 100px;/*Each grid is 100px high*/ grid-template-columns: 300px auto 300px;/*The left and right grids are both 300px, and the middle one is adaptive*/ } .layout.grid .left{ background-color: red; } .layout.grid .center{ background-color: yellow; } .layout.grid .right{ background-color: blue; } </style> <article class="left-center-right"> <div class="left"></div> <div class="center"> I am the adaptive element in the middle - grid layout</div> <div class="right"></div> </article> </section>
The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. |
<<: Vue.js implements simple folding panel
>>: Detailed explanation of MySQL Group by optimization
Table of contents Installation Steps Environment ...
After installing Docker on the Linux server, Pull...
Linux has been loved by more and more users. Why ...
1. The catalina.bat must be set to UTF-8. If I do...
This story starts with an unexpected discovery tod...
In Linux system, newly install docker and enter t...
How to modify the style of the el-select componen...
Recorded the installation and use tutorial of MyS...
Table of contents 1. unzip command 1.1 Syntax 1.2...
Based on Vue and native javascript encapsulation,...
1. Time formatting and other methods It is recomm...
1. Introduction to mysqlbackup mysqlbackup is the...
The company's business scenario requires the ...
Server Information Management server: m01 172.16....
Table of contents 1. Direct assignment 2. Shallow...