如何使按钮位于div的底部并同时位于它的中心?
这是我的代码:http: //jsfiddle.net/3QguR/1/
HTML
<div class='Center' align='center'>
<button class='btn-bot'>button-bottom</button>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS
.Center{
width:200px;
height:200px;
background:#0088cc;
margin:auto;
padding:0%;
position: relative;
top: 0; left: 0; bottom: 0; right: 0;
border-radius:5%;
}
.btn-bot{
position: absolute;
bottom: 0;
}
Run Code Online (Sandbox Code Playgroud)
Pat*_*rex 11
给父元素......
display: table; text-align: center;
Run Code Online (Sandbox Code Playgroud)
......及其子元素......
display: table-cell; vertical-align: bottom;
Run Code Online (Sandbox Code Playgroud)
这样,您不需要知道子元素更改时的宽度,因此不需要负边距或变通方法.
For example write like this if you have position absolute:
.btn-bot{
position:absolute;
margin-left:-50px;
left:50%;
width:100px;
bottom:0px;
}
Run Code Online (Sandbox Code Playgroud)
Note: give margin-left half of the width of the button.
| 归档时间: |
|
| 查看次数: |
49524 次 |
| 最近记录: |