Chapter 4 traditional CSS layout [I]-original learning points of water:
1. layout model
2. Table Layout
3. Floating Layout
Lecturer: Li Yanhui
This chapter mainly discusses the traditional layout used by CSS in HTML5 in the early days. In many cases, these layout methods are still very useful.
I. layout model
In the early days when mobile devices such as tablets and smartphones were not widely used, Web pages were designed for PC-end computer resolutions. This resolution ratio is relatively simple, basically as long as it meets the minimum resolution design. Generally, there are major resolutions such as, and. In this aspect, the length is always greater than the width. The minimum resolution is 1024*768. To prevent the scroll bar from appearing at the bottom of the browser, subtract the appropriate width, for example, subtract 28, and set the fixed length to 996. Of course, some websites have set the minimum resolution to 1280 minus the scroll bar width in the last two years, because the large display gradually becomes mainstream.
In addition to the fixed-length layout, there is also a Fluid layout, that is, the layout length is a percentage, such as 100%. No matter what resolution you use, it can be displayed in full screen. Of course, the limitations are also very large. It is only suitable for some single pages, complex pages, will lead to various reading barriers with different browsers.
We create a three-row and two-column model. The table layout and floating layout are used to build a fixed and Fluid layout. The model diagram is as follows:
Ii. Table Layout
The table layout is achieved by setting fixed cells to remove the border and padding of the table. Of course, this layout is not recommended for teaching. The most semantic part of a table is the data display of the two tables.
1. Fixed Layout
// HTML part
| header |
| aside |
section |
| footer |
// CSS part
body { margin: 0;}table { margin: 0 auto; width: 960px; border-spacing: 0;}.header { height: 120px;}.aside { width: 200px; height: 500px;}.section { width: 760px; height: 500px;}.footer { height: 120px;}
2. Fluid layout
It is very easy to change the fixed layout of a table to a Fluid layout. You only need to set the table to 100%.
// Modify the table
table { width: 100%;}
3. Floating Layout
The floating layout mainly uses the float and clear attributes.
1. Fixed Layout
// HTML part
header
aside
section
footer
// CSS part
body { width: 960px; margin: 0 auto; color: white;}header { height: 120px;}aside { width: 200px; height: 500px; float: left;}section { width: 760px; height: 500px; float: right;}footer { height: 120px; clear: both;}
2.Fluid layout
The Fluid layout only needs to change the limited length of the body element to auto or 100%. Set 20% and 80% for the left and right columns respectively.
// CSS part
body { width: auto;}aside { width: 20%;}section { width: 80%;}