Optimal web page width and its compatible implementation method

Optimal web page width and its compatible implementation method
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.

margin: 10px auto;

This line ensures that the web page will be centered at any resolution.

min-width: 780px;
max-width: 1260px;

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.

width:expression(document.body.clientWidth < 782? "780px" : document.body.clientWidth > 1262? "1260px" : "auto");

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:

#div-left{
width:50%;
}

#div-right{
width:50%;
}

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

Recommend

Detailed tutorial on using Docker to build Gitlab based on CentOS8 system

Table of contents 1. Install Docker 2. Install Gi...

Simple usage example of MySQL 8.0 recursive query

Preface This article uses the new features of MyS...

Six-step example code for JDBC connection (connecting to MySQL)

Six steps of JDBC: 1. Register the driver 2. Get ...

Ant Design Blazor component library's routing reuse multi-tab function

Recently, there has been a growing demand for imp...

WeChat applet implements calculator function

This article shares the specific code for the WeC...

The impact of limit on query performance in MySQL

I. Introduction First, let me explain the version...

Implementation example of react project from new creation to deployment

Start a new project This article mainly records t...

JavaScript Factory Pattern Explained

Table of contents Simple Factory Factory Method S...

JS Decorator Pattern and TypeScript Decorators

Table of contents Introduction to the Decorator P...

Detailed explanation of command to view log files in Linux environment

Table of contents Preface 1. cat command: 2. more...

Tomcat source code analysis of Web requests and processing

Table of contents Preface 1. EndPoint 2. Connecti...

Vue implements the drag and drop sorting function of the page div box

vue implements the drag and drop sorting function...

How can MySQL effectively prevent database deletion and running away?

Table of contents Safe Mode Settings test 1. Upda...