我想垂直居中表單。橫向可以用margin: 0 auto
完成,但我不知道如何垂直進行。垂直居中元素
* {
border: 1px solid red;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
font-family: 'Josefin Sans', sans-serif;
}
.form {
margin: 0 auto;
max-width: 600px;
padding: 50px;
width: 100%;
background-color: #2C3E50;
}
.row {
display: flex;
width: 100%;
}
.col-12 {
width: 100%;
padding: 20px;
}
input {
display: flex;
width: 100%;
padding: 10px;
background-color: #2C3E50;
border: 1px solid #FFFFFF;
font-size: 25px;
color: #ffffff;
}
<div class="form">
<form>
<div class="row">
<div class="col-12">
<input type="email" name="email" placeholder="Email Address" required>
</div>
</div>
<div class="row">
<div class="col-12">
<input type="password" name="password" placeholder="Password" required>
</div>
</div>
<button>Login</button>
</form>
</div>
[中央元件則垂直排列和霍爾與Flexbox [與...](http://stackoverflow.com/a/33049198/3597276) –
...或[使用CSS表和定位屬性](http://stackoverflow.com/a/31977476/3597276) –