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
What is the purpose of creating your own website u...
Preface Share two methods to monitor whether an e...
Interviewer: Have you read the source code of Vue...
Copy code The code is as follows: <div id=&quo...
Preface The latest version of MySQL 8.0 is 8.0.4 ...
background As the number of application systems c...
Table of contents background What are the methods...
When the height attribute of Text is defined, the ...
Table of contents Short Introduction 1. Check the...
Background requirements: The ERP system needs to ...
Use text-align, margin: 0 auto to center in CSS W...
1. Write a split script (splitNginxLog.sh) * Beca...
Classical color combinations convey power and auth...
Source: http://www.ruoyi.vip/ import Vue from ...
First, download the installation package from the...