Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to achieve the centralization of the whole html by css+div

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to achieve the whole html center of css+div. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Whether you accept div css refactoring to construct HTML, or the HTML of table forms, regardless of whether you can use div in the outermost layer, do you use float to cause the entire html page to be on the left?

It turns out that the HTML is not compatible and does not center. It is changed to the center hint.

Here CSS5 teaches everyone a small talent, easy to manage the whole page level is in the middle.

1. The fixed and trivial method of centering on the width of html pages

Add a div box to the main body of the page (the outermost layer of the page is added, plus a finished one), and set the equipment layout center (margin:0 auto) and the width of the css to the box.

The CSS code is as follows:

# t-warp {margin:0 auto;width:1000px}

It is not necessary to set the width here, just as it is usual to set the width as wide as the subject mode.

Html corresponds to additional codes in body:

Here is your original html code form

Express and clarify

If the entire page width 1000px, the original does not set the equipment html center, resulting in the left to the left, here is to configure an id=t-warp determiner to set the equipment center and width. But can not use float floating, the application will let div left or right, can not achieve the center.

Second, the method of centering on the uniform width of the subject

Often touch the head and bottom 100% width, and both ends of the page is static width, this time you need to increase three div to complete the separation center.

Add a div outermost layer between Qiujia and the bottom, set the center and width 100%

Add a div to the area at both ends, and configure the css construction to center and rest width values.

CSS Code:

.t-100 {margin:0 auto; width:100%} .t-center {margin:0 auto; width:1000px} / * if the width of the middle content of the page 1000px * /

In addition, CSS is no longer listed, simplifying your original CSS code.

HTML code in body:

100% width of the head

Part of the content assumes the width of 1000px

Part of the form assumes the width of the 1000px

Bottom 100% width

Here, the head and bottom are configured with 100% width and centered, and the two ends assume that there are two parts of the 1000px width mode, each with a width 1000px and a central DIV structure.

Although the outer head and bottom generally do not need to add div, directly configure margin:0 auto to the original # header and # footer determiners, but be careful not to use float, how to ensure the center (even if 100% width also needs to be set to center margin:0 auto).

This is the end of the article on "how to achieve the center of the whole html in css+div". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report