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

Html page supports dark mode implementation

Since 2019, both Android and IOS platforms have s...

SQL function to merge a field together

Recently, I need to query all the fields in a rel...

Solve the problem of blank gap at the bottom of Img picture

When working on a recent project, I found that th...

Mini Program Custom TabBar Component Encapsulation

This article example shares the specific code for...

HTML table markup tutorial (10): cell padding attribute CELLPADDING

Cell padding is the distance between the cell con...

Implementation of building custom images with Dockerfile

Table of contents Preface Introduction to Dockerf...

Vue routing returns the operation method of restoring page status

Route parameters, route navigation guards: retain...

Solution to the Multiple primary key defined error in MySQL

There are two ways to create a primary key: creat...

Detailed steps for yum configuration of nginx reverse proxy

Part.0 Background The company's intranet serv...

Detailed explanation of Vue login and logout

Table of contents Login business process Login fu...

Summary of HTML formatting standards for web-based email content

1. Page requirements 1) Use standard headers and ...

mysql 5.7.11 winx64 initial password change

Download the compressed version of MySQL-5.7.11-w...

Detailed steps to install Sogou input method on Ubuntu 20.04

1. Install Fcitx input framework Related dependen...