css - 将 div 垂直放置在中间

标签 css

我将如何在中间水平/垂直设置一个 div?

到目前为止,这是我的代码:

HTML

<div id="outer">
    <div id="inner">
        <div id="signin_header">
        Sign in
        </div>
    </div>
</div>

CSS

html, body {
    height: 100%;
}
html {
    display: table;
    margin: auto;
    height: 100%;
}
body {
    display: table-cell;
}
#outer {
    width: 100%;
    text-align: center;
    height: 100%;
}
#inner {
    display: inline-block;
    background-color: rgb(245, 245, 245);
    background-image: none;
    background-origin: padding-box;
    background-size: auto;
    border-bottom-color: rgb(229, 229, 229);
    border-bottom-style: solid;
    border-bottom-width: 1px;
    border-left-color: rgb(229, 229, 229);
    border-left-style: solid;
    border-left-width: 1px;
    border-right-color: rgb(229, 229, 229);
    border-right-style: solid;
    border-right-width: 1px;
    border-top-color: rgb(229, 229, 229);
    border-top-style: solid;
    border-top-width: 1px;
    display: block;
    font-family: 'segoe ui', arial, helvetica, sans-serif;
    font-size: 13px;
    width: 300px;
    padding: 25px;
}
#signin_header {
    color: rgb(34, 34, 34);
    display: block;
    font-family: 'segoe ui', arial, helvetica, sans-serif;
    font-size: 16px;
    font-weight: normal;
    height: 16px;
    line-height: 16px;
    margin-top: 0px;
    width: 283px;
    text-align: left;
}

fiddle 可以在这里找到

http://jsfiddle.net/yaFeD/

最佳答案

这就是你想要的吗?我想这就是您想要的?

html, body {
height: 100%;
}
html {
display: table;
margin: auto;
height: 100%;
}
body {
display: table-cell;
}
#outer {
width: 100%;
text-align: center;
height: 100%;
position:relative;
top:50%;
bottom:50%;
}
#inner {
display: inline-block;
background-color: rgb(245, 245, 245);
background-image: none;
background-origin: padding-box;
background-size: auto;
border-bottom-color: rgb(229, 229, 229);
border-bottom-style: solid;
border-bottom-width: 1px;
border-left-color: rgb(229, 229, 229);
border-left-style: solid;
border-left-width: 1px;
border-right-color: rgb(229, 229, 229);
border-right-style: solid;
border-right-width: 1px;
border-top-color: rgb(229, 229, 229);
border-top-style: solid;
border-top-width: 1px;
display: block;
font-family: 'segoe ui', arial, helvetica, sans-serif;
font-size: 13px;
width: 300px;
padding: 25px;
}
#signin_header {
color: rgb(34, 34, 34);
display: block;
font-family: 'segoe ui', arial, helvetica, sans-serif;
font-size: 16px;
font-weight: normal;
height: 16px;
line-height: 16px;
margin-top: 0px;
width: 283px;
text-align: left;
}

http://jsfiddle.net/EQjHz/

关于css - 将 div 垂直放置在中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15277974/

相关文章:

jQuery Body CSS 背景 URL 如果为空随机 URL

php - 需要有关 Twitter 的 CSS 和 JQuery 的帮助,例如下拉登录框

javascript - 在选项中添加图像

css - Overlay 和 Box 不透明度冲突

html - 为什么要设置一个绝对定位的 :before content element to an inline element make it overflow its parent?

html - AMP <a> 标签被 :root CSS 隐藏

javascript - 如何将文本和 Div 放置在彼此的顶部并将它们居中对齐?

css - SVG 图标在 Internet Explorer 中不起作用

html - 为什么我的输入在右侧有填充?

css 媒体查询不适用于隐藏/显示 div