gpt4 book ai didi

html - 垂直对齐中间形式就像文本一样

转载 作者:太空宇宙 更新时间:2023-11-04 03:36:04 24 4
gpt4 key购买 nike

我想垂直对齐我的表单,就像我在我的网站上垂直对齐我的文本一样。但它不起作用,我该怎么办?

enter image description here

我希望它是这样的:

enter image description here

这是我的代码 http://pastebin.com/FuCNwM6e

<head>
<!DOCTYPE html>
<html>
<head>
<title>2 Column CSS Layout</title>
<style type="text/css">
body {
margin:20px;
font-family:"Lucida Grande","Lucida Sans Unicode","Lucida Sans",Geneva,Verdana,sans-serif;
background-color:#555
}

div {
text-align:center
}

#page {
background-color:#fff;
margin:0 auto;
text-align:left;
width:755px;
padding:0 10px
}

#header {
border-bottom:0px solid #000;
height:30px;
line-height:30px
}

/* Begin Navigation Bar Styling */
#nav {
text-align:center;
line-height: 30px;
}

#nav ul {
text-align:center;
font-size:11px;
width:100%;
margin:0;
padding:0;
display:inline-block;
list-style:none;
background-color:#f2f2f2;
border-bottom:1px solid #ccc;
border-top:1px solid #ccc
}

#nav li {
margin:auto;
display:inline-block
}

#nav li a {
display:block;
padding:8px 15px;
text-decoration:none;
font-weight:700;
color:#069;
border-right:1px solid #ccc
}

#nav li a:hover {
color:#c00;
background-color:#fff
}

/* End navigation bar styling. */

#content {
height: 200px;
width:100%;
display: table;
background:none repeat scroll 0 0 none;
}

#content p {
display: table-cell;
vertical-align: middle;
}

#footer {
height:30px;
line-height:30px;
border-top: 1px solid #000;
font-size:9pt
}

#footer p {
float: right;
}

.clear {
clear: both;
}



</style>
</head>

<body>
<div id="page">
<div id="header">
<div style="float: left;">
Please Login
</div>
</div>


<div id="content">
<p>
<form action="" method="post">
<label for="un">Username</label>
<input type="text" id="un" placeholder="username" /><br/>
<label for="pw">Password</label>
<input type="password" id="pw" placeholder="password" /><br/>
<input type="submit" value="Login"/>
</form>
</p>
</div>

<div id="footer">
<div style="float: right;"> copyright 2014 </div>
</div>
</div>
</body>
</html>

最佳答案

像这样更改您的 CSS(我添加了 500 像素的高度以实现可视化)

body {
margin:20px;
font-family:"Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Geneva, Verdana, sans-serif;
background-color:#555;
height:100%;
}
div {
text-align:center
}
#page {
background-color:#fff;
margin:0 auto;
text-align:left;
width:755px;
padding:0 10px;
}
#header {
border-bottom:0px solid #000;
height:30px;
line-height:30px
}
/* Begin Navigation Bar Styling */
#nav {
text-align:center;
line-height: 30px;
}
#nav ul {
text-align:center;
font-size:11px;
width:100%;
margin:0;
padding:0;
display:inline-block;
list-style:none;
background-color:#f2f2f2;
border-bottom:1px solid #ccc;
border-top:1px solid #ccc
}
#nav li {
margin:auto;
display:inline-block
}
#nav li a {
display:block;
padding:8px 15px;
text-decoration:none;
font-weight:700;
color:#069;
border-right:1px solid #ccc
}
#nav li a:hover {
color:#c00;
background-color:#fff
}
/* End navigation bar styling. */
#content {
height: 500px;
width:100%;
background:none repeat scroll 0 0 none;
display:flex;
align-items:center;
}
#content p {
display: table-cell;
vertical-align: middle;
}
#footer {
height:30px;
line-height:30px;
border-top: 1px solid #000;
font-size:9pt
}
#content:before {
content:'';
display: inline-block;
height: 100%;
vertical-align: middle;
margin-right: -0.25em;
/* Adjusts for spacing */
}
#footer p {
float: right;
}
.clear {
clear: both;
}
form {
margin:0 auto;
width: 300px;
padding: 10px 15px;
border: #a0a0a0 solid 1px;
background: #f5f5f5;
}

See fiddle here

通过使用 flex 显示,我们可以在保持响应性的同时以任何可能的方式对齐元素,因此这将适用于固定和响应式方法,没关系

关于html - 垂直对齐中间形式就像文本一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25559452/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com