Twitter bootstrap 3 Twitter引导程序3:如何将块居中
在我看来,bootstrap3样式表中缺少类Twitter bootstrap 3 Twitter引导程序3:如何将块居中,twitter-bootstrap-3,Twitter Bootstrap 3,在我看来,bootstrap3样式表中缺少类中心块。我错过什么了吗 这里描述了它的用法,中心块可以在第12行的bootstrap 3.0中找到 在第39行中,它是Bootstrap 3.0.1版本中的新版本,因此请确保您拥有最新版本(10/29) 演示: ... 您必须将style=“width:value”与中间块类一起使用这样做效果更好(保留响应性): 你好! 中间块是个坏主意,因为它覆盖了屏幕上的一部分,您不能单击字段或按钮。 col md offset-?是更好的选择 如果类为c
中心块
。我错过什么了吗
这里描述了它的用法,中心块可以在第12行的bootstrap 3.0中找到
在第39行中,它是Bootstrap 3.0.1版本中的新版本,因此请确保您拥有最新版本(10/29) 演示:
...
您必须将style=“width:value”与中间块类一起使用这样做效果更好(保留响应性):
你好!
中间块是个坏主意,因为它覆盖了屏幕上的一部分,您不能单击字段或按钮。
col md offset-?
是更好的选择
如果类为col-sm-6
,则使用col-md-offset-3
是更好的选择。只需将数字更改为块的中心。您可以将class.center block
与style=“width:400px;max width:100%;”
结合使用,以保持响应能力
将.col md-*
类与.center block
一起使用将不起作用,因为上的浮动。以下是几种变体:
<style>
.box {
height: 200px;
width: 200px;
border: 4px solid gray;
}
</style>
<!-- This works: .container>.row>.center-block.box -->
<div class="container">
<div class="row">
<div class="center-block bg-primary box">This div is centered with .center-block</div>
</div>
</div>
<!-- This does not work -->
<div class="container">
<div class="row">
<div class="center-block bg-primary box col-xs-4">This div is centered with .center-block</div>
</div>
</div>
<!-- This is the hybrid solution from other answers:
.container>.row>.col-xs-6>.center-block.box
-->
<div class="container">
<div class="row">
<div class="col-xs-6 bg-info">
<div class="center-block bg-primary box">This div is centered with .center-block</div>
</div>
</div>
</div>
.盒子{
高度:200px;
宽度:200px;
边框:4倍纯色灰色;
}
此div以.center块为中心
此div以.center块为中心
此div以.center块为中心
要使其与col-*类一起工作,您需要将.center块包装在.col-*类中,但请记住添加另一个设置宽度的类(.box),或者通过给.center块一个宽度来改变它本身
请在上查看。我们可以查看您的工作吗?工作正常,但由于row类的原因,会给出一个水平滚动条。更多信息,您可以将class.center block
与style=“width:400px;max width:100%;”
结合使用,以保持响应能力。
<style>
.box {
height: 200px;
width: 200px;
border: 4px solid gray;
}
</style>
<!-- This works: .container>.row>.center-block.box -->
<div class="container">
<div class="row">
<div class="center-block bg-primary box">This div is centered with .center-block</div>
</div>
</div>
<!-- This does not work -->
<div class="container">
<div class="row">
<div class="center-block bg-primary box col-xs-4">This div is centered with .center-block</div>
</div>
</div>
<!-- This is the hybrid solution from other answers:
.container>.row>.col-xs-6>.center-block.box
-->
<div class="container">
<div class="row">
<div class="col-xs-6 bg-info">
<div class="center-block bg-primary box">This div is centered with .center-block</div>
</div>
</div>
</div>