我在这里有一个网站:http://americanbitcoinacademy.com/user-login/
正如您所见,表格尚未集中。
“用户名”,“密码”,“记住我”都居中,必须左对齐文字。
我想将表单居中,然后文本对齐左边的用户名,密码和记住我的标签..使用inspect element工具我该怎么做?
这是我的CSS:
@import url(https://fonts.googleapis.com/css?family=Roboto:300);
.login-page {
width: 360px;
padding: 8% 0 0;
margin: auto;
}
.form {
position: relative;
z-index: 1;
background: #FFFFFF;
max-width: 360px;
margin: 0 auto 100px;
padding: 45px;
text-align: center;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}
.form input {
font-family: "Roboto", sans-serif;
outline: 0;
background: #f2f2f2;
width: 100%;
border: 0;
margin: 0 0 15px;
padding: 15px;
box-sizing: border-box;
font-size: 14px;
}
.form button {
font-family: "Roboto", sans-serif;
text-transform: uppercase;
outline: 0;
background: #dd374d;
width: 100%;
border: 0;
padding: 15px;
color: #FFFFFF;
font-size: 14px;
-webkit-transition: all 0.3 ease;
transition: all 0.3 ease;
cursor: pointer;
}
.form button:hover,.form button:active,.form button:focus {
background: #43A047;
}
.form .message {
margin: 15px 0 0;
color: #b3b3b3;
font-size: 12px;
}
.form .message a {
color: #4CAF50;
text-decoration: none;
}
.form .register-form {
display: none;
}
body {
background: #ecf0f1; /* fallback for old browsers */
font-family: "Roboto", sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.page-heading{ display: none; }
请帮忙!
答案 0 :(得分:1)
从此课程中删除 text-align:center; -
.form {
position: relative;
z-index: 1;
background: #FFFFFF;
max-width: 360px;
margin: 0 auto 100px;
padding: 45px;
text-align: center;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}
并将此CSS添加到记住我复选框width: auto;
避免使用元素级CSS特性,例如:.form input
总是使用类。
MDN:https://developer.mozilla.org/en/docs/Web/CSS/Specificity
答案 1 :(得分:1)
您可以删除
text-align:center;
来自表单元素。
答案 2 :(得分:1)
删除text-align:center
表单.form
类
.form {
position: relative;
z-index: 1;
background: #FFFFFF;
max-width: 360px;
margin: 0 auto 100px;
padding: 45px;
text-align: center;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}
并删除col-md-9
类div
content
作为ID
<div id="content" class="col-md-9" role="main">
答案 3 :(得分:1)
从班级text-align:center
移除form
并将班级ub div从col-md-9
更改为col-md-12
<div id="content" role="main" class="col-md-12">
....
</div>
您更新的CSS将是
.form {
position: relative;
z-index: 1;
/* text-align:center; Remove this line */
background: #FFFFFF;
max-width: 360px;
margin: 0 auto 100px;
padding: 45px;
text-align: left;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}
答案 4 :(得分:1)
更改否。 1 - 强>
<div id="content" class="col-md-9" role="main"></div> to
<div id="content" class="col-md-12" role="main"></div>
更改否。 2 -
.form {
position: relative;
z-index: 1;
background: #FFFFFF;
max-width: 360px;
margin: 0 auto 100px;
padding: 45px;
text-align: center;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
} to
.form {
position: relative;
z-index: 1;
background: #FFFFFF;
max-width: 360px;
margin: 0 auto 100px;
padding: 45px;
text-align: left;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}
更改否。 3-添加以下Css -
.login-remember label{ width: 100%;}
.form .login-remember input{width: auto;}
答案 5 :(得分:1)
实际上,表单本身 在其容器<article class="single-page-content">
内居中。你只需要给那篇文章,或者实际上它的父元素(即id=content
的div)全宽。
对于表单内的左对齐,只需将text-align: center
更改为left
.form
.login-page {
width: 360px;
padding: 8% 0 0;
margin: auto;
}
.form {
position: relative;
z-index: 1;
background: #FFFFFF;
max-width: 360px;
margin: 0 auto 100px;
padding: 45px;
text-align: left;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}
.form input {
font-family: "Roboto", sans-serif;
outline: 0;
background: #f2f2f2;
width: 100%;
border: 0;
margin: 0 0 15px;
padding: 15px;
box-sizing: border-box;
font-size: 14px;
}
.form button {
font-family: "Roboto", sans-serif;
text-transform: uppercase;
outline: 0;
background: #dd374d;
width: 100%;
border: 0;
padding: 15px;
color: #FFFFFF;
font-size: 14px;
-webkit-transition: all 0.3 ease;
transition: all 0.3 ease;
cursor: pointer;
}
.form button:hover,.form button:active,.form button:focus {
background: #43A047;
}
.form .message {
margin: 15px 0 0;
color: #b3b3b3;
font-size: 12px;
}
.form .message a {
color: #4CAF50;
text-decoration: none;
}
.form .register-form {
display: none;
}
body {
background: #ecf0f1; /* fallback for old browsers */
font-family: "Roboto", sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.page-heading{ display: none; }
&#13;
<div id="body" >
<div class="container">
<div class="content-pad-3x">
<div class="row">
<div id="content" class="col-md-9" role="main">
<article class="single-page-content">
<div class="login-page">
<div class="form">
<form class="login-form">
<form name="loginform" id="loginform" action="http://americanbitcoinacademy.com/wp-login.php" method="post">
<p class="login-username">
<label for="user_login">Username:</label>
<input type="text" name="log" id="user_login" class="input" value="" size="20" />
</p>
<p class="login-password">
<label for="user_pass">Password:</label>
<input type="password" name="pwd" id="user_pass" class="input" value="" size="20" />
</p>
<p class="login-remember"><label><input name="rememberme" type="checkbox" id="rememberme" value="forever" /> Remember Me</label></p>
<p class="login-submit">
<input type="submit" name="wp-submit" id="wp-submit" class="button button-primary" value="Log In" />
<input type="hidden" name="redirect_to" value="" />
</p>
</form><br />
<a href="/order">Click here</a> to become a full member…<br />
<br />
</form>
</div>
</div>
&#13;
答案 6 :(得分:0)
标签中留下的文字..
.form label{width:100%;text-align:left;}
如果您将中文<div id="content" class="col-md-9" role="main">
更改为<div id="content" class="col-md-12" role="main">
,则表格将居中。
干杯!