1. When designing a web page, determining the width is a very troublesome task. Taking jb51.net as an example, according to Google Analytics statistics, over the past six months, there have been a total of 81 types of screen resolutions for visitors. The smallest resolution is 122x160, which should be a mobile phone; the largest resolution is 3360x1050, God knows what device it is. It is easy to imagine how difficult it is for a web page to present satisfactory results on screens of such different sizes. For example, a 400px wide image will take up 50% of the width on an 800px screen, but only 20% on a 1920px screen (a popular setting for Windows Vista). 2. Currently, there are about 6 common screen resolution widths: 800px, 1024px, 1280px, 1440px, 1680px and 1920px. Among them, 1024px is the most common, but with the popularity of large-screen displays, higher resolutions are becoming more and more common. There are two common solutions: The first method: Use JavaScript to select CSS style sheet files according to different client resolutions. The specific method can be seen here. The second method: Use Fluid Width Layout to achieve adaptive width of web page. The advantage of the first method is that it can use completely different layouts according to different screen resolutions. The disadvantage is that it requires designing and maintaining multiple style sheets, which is more troublesome. The second method uses only one style sheet, which is more convenient. The following article will discuss how to implement the second method based on the solution on css-tricks, which is actually very simple. 3. First, the default width of the web page is determined to meet the display width of 1024px. This is not only because 1024x768 is the most common resolution now, but also because this width is most suitable for web pages: 1) It can accommodate enough content, enough for a three-column layout; 2) A single line of text should not be too long, 1024px is the limit, otherwise it is easy to cause reading fatigue; 3) Under the current Internet bandwidth conditions, it is difficult for web pages to use large-size images required by large resolutions. Secondly, the width of the web page will automatically change within the range of 780px-1260px, that is, the minimum is not less than 780px and the maximum is not more than 1280px. Finally, for larger resolutions, web content is automatically centered. 4. Here is how to write a CSS file, just 4 lines. It should be noted that these lines of statements are all for the entire page, that is, the body tag or the outermost div area.
This line ensures that the web page will be centered at any resolution.
These two lines specify the minimum and maximum width of the web page. Note that IE6 does not support these two lines, that is, they are invalid in IE6. This line is a workaround for IE6. It uses CSS expressions and can also be implemented through javascript. In addition, if you want the inner blocks to automatically expand and contract, their widths can be expressed in percentages, for example:
The final result and source code download can be found here. By changing the size of the browser window, you can find that the web page will automatically scale within the range of 780px-1260px. 5. Finally, it is recommended that you do not blindly use high resolution when using computers, as it is not very meaningful. |
<<: Detailed explanation of Vue slot
>>: Introduction to container of() function in Linux kernel programming
One day, the leader put forward a requirement to ...
Since 2019, both Android and IOS platforms have s...
Recently, I need to query all the fields in a rel...
When working on a recent project, I found that th...
This article example shares the specific code for...
Cell padding is the distance between the cell con...
Table of contents Preface Introduction to Dockerf...
Route parameters, route navigation guards: retain...
There are two ways to create a primary key: creat...
Part.0 Background The company's intranet serv...
Table of contents Login business process Login fu...
1. Page requirements 1) Use standard headers and ...
Download the compressed version of MySQL-5.7.11-w...
A few days ago, I saw an example written by @Kyle...
1. Install Fcitx input framework Related dependen...