html - bootstrap(css):如何在页面中心布局登录表单
问题描述
现在登录表单是左侧的布局。. 我想在中心布局,我尝试了一些css样式,但是失败了。当我在代码中删除 '{% extends "common/base.html" %} ' 时,虽然没有 css 样式和导航栏,但表单可以在中间。
我的 html 代码如下,我添加了 css 样式。
{% extends "common/base.html" %}
{% block content %}
<div class="main-login", id="parent">
<form align="center" action="/login" method="POST" >
<div class="login-screen">
<div class="app-title">
<h1>Login</h1>
</div>
<div class="login-form">
<div class="control-group">
<input type="text" class="login-field" value="" placeholder="username" name="username">
<label class="login-field-icon fui-user" for="login-name"></label>
</div>
<div class="control-group">
<input type="password" class="login-field" value="" placeholder="password" name="password">
<label class="login-field-icon fui-lock" for="login-pass"></label>
</div>
<input type="submit" value="Log in" class="btn btn-primary btn-large btn-block" >
<br>
<p>{{ _('New User?') }} <a href="{{ url_for('auth.register') }}">{{ _('Click to Register!') }}</a></p>
<p>
{{ _('Forgot Your Password?') }}
<a href="{{ url_for('auth.reset_password_request') }}">{{ _('Click to Reset It') }}</a>
</p>
</div>
</div>
</form>
</div>]
我的CSS代码:
.main-login{
padding-top: 100px;
text-align: center;
width:500px;
/*align-items: center;*/
vertical-align: middle;
}
#parent {
/*display: table;*/
width: 50%;
vertical-align: middle;
text-align: center;
}
.login {
margin: 20px auto;
width: 300px;
}
.login-screen {
/*background-color: #FFF;*/
padding-top: 1000px;
background-color: #3498DB;
padding: 20px;
border-radius: 5px;
text-align: center;
}
.app-title {
text-align: center;
color: #777;
}
.login-form {
text-align: center;
}
.control-group {
margin-bottom: 10px;
}
input {
text-align: center;
background-color: #ECF0F1;
border: 2px solid transparent;
border-radius: 3px;
font-size: 16px;
font-weight: 200;
padding: 10px 0;
width: 250px;
transition: border .5s;
}
input:focus {
border: 2px solid #3498DB;
box-shadow: none;
}
.btn {
border: 2px solid transparent;
background: #3498DB;
color: #ffffff;
font-size: 16px;
line-height: 25px;
padding: 10px 0;
text-decoration: none;
text-shadow: none;
border-radius: 3px;
box-shadow: none;
transition: 0.25s;
display: block;
width: 250px;
margin: 0 auto;
}
.btn:hover {
background-color: #2980B9;
}
.login-link {
font-size: 12px;
color: #444;
display: block;
margin-top: 12px;
}
使用 vsevolodts 的回答后中间的图像我想使下面的登录按钮的长度与密码形式相同:
解决方案
将下一个 CSS 技巧应用于主块:
margin-left:auto;
margin-right:auto;
推荐阅读
- vue.js - 数据表 vuetify 事件和渲染不适用于每页行下拉
- python - 将 OSMnx 图中的封闭线串转换为多面体
- deno - 如何检查不受信任的代码是否可以安全执行?
- flutter - Flutter Package Publish Error 说包不兼容
- amazon-web-services - Auto Scaling 组 AWS
- node.js - [Teams][botbuilder] Adaptive Cards TextBlock 中的空行
- python - 无法连接到 IMAP SERVER (gmail)
- css - mui 材料 responsiveFontSizes 不处理 body2
- javascript - 轴标签中的 ChartJS 彩色框
- ruby - bash 解密和 ruby 一样