【发布时间】:2020-10-21 10:22:32
【问题描述】:
我正在尝试为我的 Web 应用程序垂直和水平对齐登录 div,但我遇到了一些麻烦,因为我对使用 CSS 相当缺乏经验。我已经附上了它在页面上的样子的图像,以及我的 HTML 和从 Web 开发工具中获取的 div 样式,以查看是否有人可以提供帮助。出于某种原因,虽然登录 div 看起来很接近,但它并没有水平居中,我尝试了一些垂直对齐的方法,但它们也没有工作。提前感谢您的任何建议。
<c:url var="loginUrl" value="/login" />
<div class="outer">
<div class="row" style="vertical-align: middle; display: inline-block; width: 35%;">
<div class="col-md-12 col-md-offset-2">
<c:if test="${param.error != null}">
<div class="login-error">Incorrect username or password</div>
</c:if>
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">User Login</div>
</div>
<div class="panel-body">
<form method="post" action="${loginUrl}" class="login-form">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
<div class="input-group">
<input type="text" name="username" placeholder="Username"
class="form-control" />
</div>
<div class="input-group">
<input type="password" name="password" placeholder="Password"
class="form-control" />
</div>
<div class="input-group">
<button type="submit" class="btn-primary float-right">Sign In</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
text-size-adjust: 100%;
-webkit-tap-highlight-color: transparent;
--blue: #007bff;
--indigo: #6610f2;
--purple: #6f42c1;
--pink: #e83e8c;
--red: #dc3545;
--orange: #fd7e14;
--yellow: #ffc107;
--green: #28a745;
--teal: #20c997;
--cyan: #17a2b8;
--white: #fff;
--gray: #6c757d;
--gray-dark: #343a40;
--primary: #007bff;
--secondary: #6c757d;
--success: #28a745;
--info: #17a2b8;
--warning: #ffc107;
--danger: #dc3545;
--light: #f8f9fa;
--dark: #343a40;
--breakpoint-xs: 0;
--breakpoint-sm: 576px;
--breakpoint-md: 768px;
--breakpoint-lg: 992px;
--breakpoint-xl: 1200px;
--font-family-sans-serif: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";
--font-family-monospace: SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: rgb(33, 37, 41);
text-align: center;
box-sizing: border-box;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;
vertical-align: middle;
display: inline-block;
width: 35%;
【问题讨论】:
标签: html css vertical-alignment text-alignment