Home >Web Front-end >HTML Tutorial >div css page layout centered_html/css_WEB-ITnose

div css page layout centered_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:27:231055browse

If you want to center the entire page top and bottom, they must be a whole. I added a class to the 6c04bd5ca3fcae76e30b72ad730ca86d tag so that the two parts of the body are truly included in one whole. Next, set up the overall 298b6fcf29074d60dd041d02d2dcb730:

.mainLayout {    position :absolute;    left : 50%;    top : 50%;    width : 910px;    margin-top : -270px;    margin-left : -455px;}

This is achieved using absolute positioning and negative margin values. .

left:50% will cause the entire mainlayout container to be displayed from the horizontal midpoint of the browser to the right. At this time, the left half of the browser is empty.

Then set margin-left to half of the mainlayout container, and set it to a negative value to allow the container to move to the left, that is, move the entire container from the center of the browser to the left (mainlayout container) itself half. In this way, the mainlayout container can be displayed centered on the left and right.

The principle of upper and lower centered display is the same: first top: 50% to make the container display downward from the midpoint of the vertical direction, leaving half of the space above. Then move half of the mainlayout container up so that it is vertically centered.

Original link: http://my.oschina.net/suyewanwan/blog/110784

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn