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

Install CentOS 7 on VMware14 Graphic Tutorial

Introduction to CentOS CentOS is an enterprise-cl...

Example code of vue custom component to implement v-model two-way binding data

In the project, you will encounter custom public ...

Detailed explanation of the use of docker tag and docker push

Docker tag detailed explanation The use of the do...

Use nginx to configure domain name-based virtual hosts

1. What is a virtual host? Virtual hosts use spec...

Detailed explanation of the properties and functions of Vuex

Table of contents What is Vuex? Five properties o...

How to install suPHP for PHP5 on CentOS 7 (Peng Ge)

By default, PHP on CentOS 7 runs as apache or nob...

Timeline implementation method based on ccs3

In web projects we often use the timeline control...

Analyze how uniapp dynamically obtains the interface domain name

background The interface domain name is not hard-...

How to make spaces have the same width in IE and FF?

body{font-size:12px; font-family:"宋体";}...

LINUX Checks whether the port is occupied

I have never been able to figure out whether the ...

Summary of the application of decorative elements in web design

<br />Preface: Before reading this tutorial,...

Solution to ERROR 1054 (42S22) when changing password in MySQL 5.7

I have newly installed MySQL 5.7. When I log in, ...

Solution to Docker image downloading too slowly

Docker image download is stuck or too slow I sear...

Install ethereum/Ethereum from scratch under CentOS7

Table of contents Preface Add sudo write permissi...

Web page creation for beginners: Learn to use HTML's hyperlink A tag

The hyperlink a tag represents a link point and i...