gpt4 book ai didi

html - 物体不会居中

转载 作者:太空宇宙 更新时间:2023-11-04 08:51:23 25 4
gpt4 key购买 nike

我真的不好意思问这个,但我不知道为什么我的登录对象不会居中。我对此很陌生,很抱歉这是一个愚蠢的问题。我希望有一个人可以帮助我。这是我的代码:

<div id="main">
<div id="login">
<h2>Login</h2>
<form action="" method="post">
<label>Username :</label>
<input id="name" name="username" placeholder="username" type="text">
<label>Password :</label>
<input id="password" name="password" placeholder="**********" type="password">
<input name="submit" type="submit" value=" Login ">
<span><?php echo $error; ?></span>
</form>
</div>
</div>

CSS:

#main {
width:960px;
margin:50px auto;
font-family:raleway;
text-align: center;
}
span {
color:red
}
h2 {
background-color: white;
text-align:center;
border-radius:10px 10px 0 0;
margin:-10px -40px;
padding:15px
}
hr {
border:0;
border-bottom:1px solid #ccc;
margin:10px -40px;
margin-bottom:30px
}
#login {
width:600px;
float:left;
border-radius:10px;
font-family:raleway;
border:2px solid #ccc;
padding:10px 40px 25px;
margin-top:70px;
}
input[type=text],input[type=password] {
width:100%;
padding:10px;
margin-top:8px;
border:1px solid #ccc;
padding-left:5px;
font-size:16px;
font-family:raleway
}
input[type=submit] {
width:103.5%;
background-color: #2F8059;
color:#fff;
border:2px solid #2F8059;
padding:10px;
font-size:20px;
cursor:pointer;
border-radius:5px;
margin-bottom:15px;
height: 50px;

}
#profile {
padding:50px;
border:1px dashed grey;
font-size:20px;
background-color:#DCE6F7;
text-align: center;

}
#logout {
float:right;
padding:5px;
border:dashed 1px gray
}
a {
text-decoration:none;
color:#6495ed
}
i {
color:#6495ed
}

最佳答案

#login的规则中,去掉float: left,插入display: inline-block,这样文本居中它的父级可以是有效的:

#main {
width: 960px;
margin: 50px auto;
font-family: raleway;
text-align: center;
}

span {
color: red
}

h2 {
background-color: white;
text-align: center;
border-radius: 10px 10px 0 0;
margin: -10px -40px;
padding: 15px
}

hr {
border: 0;
border-bottom: 1px solid #ccc;
margin: 10px -40px;
margin-bottom: 30px
}

#login {
width: 600px;
display: inline-block;
border-radius: 10px;
font-family: raleway;
border: 2px solid #ccc;
padding: 10px 40px 25px;
margin-top: 70px;
}

input[type=text],
input[type=password] {
width: 100%;
padding: 10px;
margin-top: 8px;
border: 1px solid #ccc;
padding-left: 5px;
font-size: 16px;
font-family: raleway
}

input[type=submit] {
width: 103.5%;
background-color: #2F8059;
color: #fff;
border: 2px solid #2F8059;
padding: 10px;
font-size: 20px;
cursor: pointer;
border-radius: 5px;
margin-bottom: 15px;
height: 50px;
}

#profile {
padding: 50px;
border: 1px dashed grey;
font-size: 20px;
background-color: #DCE6F7;
text-align: center;
}

#logout {
float: right;
padding: 5px;
border: dashed 1px gray
}

a {
text-decoration: none;
color: #6495ed
}

i {
color: #6495ed
}
<div id="main">
<div id="login">
<h2>Login</h2>
<form action="" method="post">
<label>Username :</label>
<input id="name" name="username" placeholder="username" type="text">
<label>Password :</label>
<input id="password" name="password" placeholder="**********" type="password">
<input name="submit" type="submit" value=" Login ">
<span><?php echo $error; ?></span>
</form>
</div>
</div>

关于html - 物体不会居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43425724/

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