【问题标题】:CSS to vertically align a button in purecssCSS 在 purecss 中垂直对齐按钮
【发布时间】:2016-06-26 22:58:03
【问题描述】:
我在 div 内有一个按钮,该按钮当前位于 div 的顶部。我想将它垂直居中在父 div 内。
.button-login {
background-color: white;
border: 2px solid #01BDE0;
border-radius: 4px;
color:#01BDE0;
width: 100%;
height:46px;
vertical-align: middle;
font-size: 1vw;
display: block;
}
这是按钮的 css。
<div class=" pure-u-1 pure-u-md-2-24"><button class="button-login">LOG IN</button></div>
这是html部分。
我试过垂直对齐它不起作用。
【问题讨论】:
标签:
html
css
yui-pure-css
【解决方案1】:
试试这个...
<style>
.pure-u-1 { width:100%;}
.center {height: 500px; background-color: #222;}
.vertical-align {position: relative; top: 50%; transform: translateY(-50%); }
</style>
<div class=" pure-u-1 pure-u-md-2-24">
<div class="center" align="center">
<div class="vertical-align">
<button class="button-login">LOG IN</button>
</div>
</div>
</div>
【解决方案2】:
.video-contant {
position: absolute;
background: rgba(7, 7, 7, 0.52);
width: 100%;
top: 0px;
height: 100%;
display: table;
}
.hctr {
display: table-cell;
vertical-align: middle;
text-align: center;
color: #fff;
width: 100%;
overflow: hidden;
}
<div class="video-contant">
<div class="hctr">
<button>onewebbell.com<button>
</div>
</div>