Rus*_*hah 6 html javascript css jquery twitter-bootstrap
我想垂直居中一个模态.我在Google上搜索了很多但没有发现任何有用的信息.这是我的代码:
function inactive(id, ths) {
$("#confirmation").modal("show");
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="modal fade bs-example-modal-sm" id="confirmation" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Are you sure you want to inactivate it?</h4>
</div>
<div class="modal-body">
<div class="form-group">
<input type="text" class="form-control" name="captcha" id="cval" placeholder="enter captcha">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">No</button>
<button type="button" class="btn btn-primary" id="yes">Yes</button>
</div>
</div>
</div>
</div>Run Code Online (Sandbox Code Playgroud)
我怎样才能垂直居中?
brk*_*brk 20
没有测试,但你可以试试这个
.yourElement{
position: relative;
top: 50%;
transform: translateY(-50%);
}
Run Code Online (Sandbox Code Playgroud)
因为它看起来像一个引导模态,Checkout this Fiddle(jsFiddle).
尝试
.modal-dialog {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) !important;
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
通过添加位置和变换属性,您不会让它在所有宽度和设备上居中,而且一直计算它可能是一个乏味的过程。这是通过仅设置“.modal-dialog”类的样式来实现的效果
/* Center a bootstrap modal Vertically and horizontally */
.modal-dialog {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}
/* and Viola! */
Run Code Online (Sandbox Code Playgroud)
为此有一个特定的引导程序类(v4.1):
将.modal-dialog-centered添加到.modal-dialog以使模态垂直居中。
资料来源:https : //getbootstrap.com/docs/4.1/components/modal/#vertically-centered
| 归档时间: |
|
| 查看次数: |
15387 次 |
| 最近记录: |