简体   繁体   English

如何居中并垂直对齐到页面内部的div?

[英]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. 我想要的是一个div,高度为410px,宽度为756px,位于屏幕中央。 So vertically and horizontally. 所以垂直和水平。 I then want to be able to put other 's inside it with content. 然后,我希望能够将other的内容放入其中。 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; 使用margin: auto; .

HTML: HTML:

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

CSS: CSS:

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

See this link for vertical centering . 有关垂直居中的信息,请参见此链接

Here's a fully working example . 这是一个完整的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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