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
1. Use the speed control function to control the ...
Table of contents Mainly used Postman functions D...
The simplest application of store in Vue is globa...
1. MIME: Multipurpose Internet Mail Extensions Th...
<br />Web Design and Production Test Part I ...
Table of contents 1. Operators Summarize 1. Opera...
Table of contents Code Optimization Using key in ...
The first tutorial for installing MySQL-5.7.19 ve...
First, let’s understand what MySQL is? MySQL is a...
A style sheet describes how a document should be ...
Copy code The code is as follows: <html> &l...
Loading rules of require method Prioritize loadin...
Preface We all know that startups initially use m...
Today, I set up a newly purchased Alibaba Cloud E...
Table of contents rc.local method chkconfig metho...