Html 物化框架中的水平和垂直对齐
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31854696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Horizontal and vertical alignment in materialize framework
提问by Ordidaad
How can I center the login box both horizontal and vertical?
如何将登录框水平和垂直居中?
Here is my structure:
这是我的结构:
<div class="container">
<div class="row">
<div class="col s12 m6">
<div class="card">
<div class="card-content">
<span class="card-title black-text">Sign In</span>
<form>
<div class="row">
<div class="input-field col s12">
<input placeholder="Placeholder" id="firstname" type="text" class="validate">
<label for="firstname" class="active">First Name</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input placeholder="Placeholder" id="lastname" type="text" class="validate">
<label for="lastname" class="active">Last Name</label>
</div>
</div>
</form>
</div>
<div class="card-action">
<input type="submit" class="btn" value="Sign In">
</div>
</div>
</div>
I tried using valign-wrapper
and valign
class but it does not work.
我尝试使用valign-wrapper
和valign
类,但它不起作用。
回答by friek108
Here is the proper (materializecss) way to do it and without messy css:
这是正确的 (materializecss) 方法,没有凌乱的 css:
<div class="valign-wrapper" style="width:100%;height:100%;position: absolute;">
<div class="valign" style="width:100%;">
<div class="container">
<div class="row">
<div class="col s12 m6 offset-m3">
<div class="card">
<div class="card-content">
<span class="card-title black-text">Sign In</span>
<form>
<div class="row">
<div class="input-field col s12">
<input placeholder="Placeholder" id="firstname" type="text" class="validate">
<label for="firstname" class="active">First Name</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input placeholder="Placeholder" id="lastname" type="text" class="validate">
<label for="lastname" class="active">Last Name</label>
</div>
</div>
</form>
</div>
<div class="card-action">
<input type="submit" class="btn" value="Sign In">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
回答by dc-aoxn
Simply use offset
to align. Offset the card view by half of what's left.
只需用于offset
对齐。将卡片视图偏移一半。
<div class="container">
<div class="row">
<div class="col s12 m6 offset-m3">
<div class="card">
<div class="card-content">
<span class="card-title black-text">Sign In</span>
<form>
<div class="row">
<div class="input-field col s12">
<input placeholder="Placeholder" id="firstname" type="text" class="validate">
<label for="firstname" class="active">First Name</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input placeholder="Placeholder" id="lastname" type="text" class="validate">
<label for="lastname" class="active">Last Name</label>
</div>
</div>
</form>
</div>
<div class="card-action">
<input type="submit" class="btn" value="Sign In">
</div>
</div>
</div>
回答by Kapil
Try to this solution, I hope it can help you
尝试这个解决方案,我希望它可以帮助你
.card {
position: absolute;
left: 50%;
top: 50%;
-moz-transform: translate(-50%, -50%)
-webkit-transform: translate(-50%, -50%)
-ms-transform: translate(-50%, -50%)
-o-transform: translate(-50%, -50%)
transform: translate(-50%, -50%);
}
Also you can try
你也可以试试
body (or container-div) {
display: flex;
align-items: center;
justify-content: center;
}
回答by Jinu Kurian
have you tried
你有没有尝试过
.col.s12.m6{
float: none;
margin: 100px auto;
width: 300px;
height: 300px;
}
Check out this fiddle, http://fiddle.jshell.net/8vu47fb2/
看看这个小提琴, http://fiddle.jshell.net/8vu47fb2/
use margin-top, margin-bottom to align the box at center.
使用 margin-top, margin-bottom 在中心对齐框。
回答by repzero
Set text align property of div
设置 div 的文本对齐属性
<div class="input-field col s12" style="text-align:center">
<div class="input-field col s12" style="text-align:center">
<input placeholder="Placeholder" id="lastname" type="text" class="validate" style="vertical-align:middle">
<input placeholder="Placeholder" id="firstname" type="text" class="validate" style="vertical-align:middle">
see here http://jsfiddle.net/kuqqdswg/
回答by uruapanmexicansong
You need to herit full height, starting at html
and body
tags.
你需要继承全高,从html
和body
标签开始。