简体   繁体   中英

How to center and vertically align to middle a div inside a page?

I have searched the internet for countless hours looking for a solution and I can never seem to find it. What if I had a log in page and I wanted to have it completely centered in the center of the page.

I've never figured out how to do this and hopefully someone can help me put and end to this lack of knowledge of mine.

Here is an example 在此处输入图片说明

What I want is to have a div with a height of 410px and a width of 756px to be centered on the screen. So vertically and horizontally. I then want to be able to put other 's inside it with content. For example maybe I want to put a login page in there or a blog post or anything.

Major thanks in advance!

Use margin: auto; .

HTML:

​<div class="middle">middle</div>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

CSS:

​.middle
{
    width: 100px;
    height: 50px;
    border: solid 1px red;
    margin: auto;
}​

See this link for vertical centering .

Here's a fully working example .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM