我想把我的7个div放在中心,我不知道该怎么做。任何的想法?我不想单独更改所有元素的边距,正如您在图片上看到的那样,与按钮相比,div不是居中的,并且存在12列引导问题
<style type="text/css">
.properbut{
height: 180px;
display: block;
margin-left: auto;
margin-right: auto;
display: table-cell;
vertical-align: middle;
}
.fonts{
font-family:Georgia,serif;
color:#4E443C;
font-variant: small-caps;
text-transform: none;
font-weight: 100;
font-size: 30px
}
</style>
<div class="container">
<br><br><br><br>
<div class="jumbotron">
<br><br><br><br><br><br>
<div class="row">
<div class ="col-md-2">
</div>
<div class ="col-md-1 ">
<img src="<?php echo asset_url();?>media/img/kalendarz/pon.png" style="height: 60px;">
</div>
<div class ="col-md-1 ">
<img src="<?php echo asset_url();?>media/img/kalendarz/wto.png" style="height: 60px">
</div>
<div class ="col-md-1 ">
<img src="<?php echo asset_url();?>media/img/kalendarz/sro.png" style="height: 60px">
</div>
<div class ="col-md-1 ">
<img src="<?php echo asset_url();?>media/img/kalendarz/czw.png" style="height: 60px">
</div>
<div class ="col-md-1 ">
<img src="<?php echo asset_url();?>media/img/kalendarz/pia.png" style="height: 60px">
</div>
<div class ="col-md-1 ">
<img src="<?php echo asset_url();?>media/img/kalendarz/sob.png" style="height: 60px">
</div>
<div class ="col-md-1">
<img src="<?php echo asset_url();?>media/img/kalendarz/niedz.png" style="height: 60px">
</div>
<div class ="col-md-3">
</div>
</div>
<br><br><br><br><br><br>
<div class="row container" >
<div>
<button class="properbut btn btn-primary col-md-3 fonts" type="submit" style="margin-left: 130px;">Powtórki</button>
</div>
<div class="col-md-3" >
<p class="text-center fonts" style="margin-top: 7px; font-size: 30px;">Co dzisiaj zrobisz aby osiągnąć swój cel?</p>
</div>
<div>
<button class="properbut btn btn-warning col-md-3 fonts" type="submit">Lekcje audio</button>
</div>
</div>
<br><br><br><br><br><br><br><br>
<br><br><br><br>
</div>
答案 0 :(得分:12)
CSS样式:
/* centered columns styles */
.row-centered {
text-align:center;
}
.col-centered {
display:inline-block;
float:none;
/* reset the text-align */
text-align:left;
/* inline-block space fix */
margin-right:-4px;
}
HTML:
<div class="row row-centered">
<div class ="col-md-1 col-centered">
<img src="http://placehold.it/100x100" style="height: 60px;">
</div>
<div class ="col-md-1 col-centered">
<img src="http://placehold.it/100x100" style="height: 60px;">
</div>
<div class ="col-md-1 col-centered">
<img src="http://placehold.it/100x100" style="height: 60px;">
</div>
<div class ="col-md-1 col-centered">
<img src="http://placehold.it/100x100" style="height: 60px;">
</div>
<div class ="col-md-1 col-centered">
<img src="http://placehold.it/100x100" style="height: 60px;">
</div>
<div class ="col-md-1 col-centered">
<img src="http://placehold.it/100x100" style="height: 60px;">
</div>
<div class ="col-md-1 col-centered">
<img src="http://placehold.it/100x100" style="height: 60px;">
</div>
</div><!-- row -->
这可以帮助您解决问题。
答案 1 :(得分:5)
你需要像this这样的东西吗?
.row {
text-align: center;
}
.col-md-1 {
display:inline-block;
}
答案 2 :(得分:2)
首先。如果你想在中心有7张照片,你需要14列! 转到http://getbootstrap.com/customize/#grid-system。列的数量是14.(或28,以制作更精确的网格系统)。比下载它并使用这个css。
在标准配置中:
col-xs -...电话(&lt; 768px)。 例如,col-xs-12是设备中的完整宽度&lt; 768px
col-sm -...小型设备&gt; = 768px且&lt; 992px。例如,col-sm-6表示该区域中设备宽度的一半
col-md -...媒体设备桌面&gt; = 992px和&lt; 1200像素
http://getbootstrap.com/css/#grid-options
如果您使用Bootstrap,则必须了解此信息。 Bootstrap与偏移一起使用,因此您不需要使用margin-left,margin-right。
无需使用
display: block;
margin-left: auto;
margin-right: auto;
display: table-cell;
在班级&#34;正确但&#34;!
http://getbootstrap.com/css/#grid-offsetting
而不是<br><br><br>....
使用填充。
这是一个带有14列网格的工作示例:
<强> CSS 强>
.properbut {
height: 180px;
}
.p50 {
padding: 50px;
}
.jumbotron img {
height: 60px;
}
.fonts {
font-family: Georgia,serif;
color: #4E443C;
font-variant: small-caps;
text-transform: none;
font-weight: 100;
font-size: 30px;
}
<强> HTML 强>
<div class="container">
<div class="jumbotron">
<div class="row text-center p50">
<div class ="col-xs-2 col-sm-2 col-md-2 col-lg-2 ">
<img src="<?php echo asset_url();?>media/img/kalendarz/pon.png" >
</div>
<div class ="col-xs-2 col-sm-2 col-md-2 col-lg-2 ">
<img src="<?php echo asset_url();?>media/img/kalendarz/wto.png" >
</div>
<div class ="col-xs-2 col-sm-2 col-md-2 col-lg-2 ">
<img src="<?php echo asset_url();?>media/img/kalendarz/sro.png">
</div>
<div class ="col-xs-2 col-sm-2 col-md-2 col-lg-2 ">
<img src="<?php echo asset_url();?>media/img/kalendarz/czw.png">
</div>
<div class ="col-xs-2 col-sm-2 col-md-2 col-lg-2 ">
<img src="<?php echo asset_url();?>media/img/kalendarz/pia.png">
</div>
<div class ="col-xs-2 col-sm-2 col-md-2 col-lg-2 ">
<img src="<?php echo asset_url();?>media/img/kalendarz/sob.png">
</div>
<div class ="col-xs-2 col-sm-2 col-md-2 col-lg-2">
<img src="<?php echo asset_url();?>media/img/kalendarz/niedz.png">
</div>
</div><!-- row -->
<div class="row p50">
<div>
<button class="properbut btn btn-primary col-xs-10 col-xs-offset-2 col-sm-8 col-sm-offset-3 col-md-5 col-md-offset-0 col-lg-3 col-lg-offset-1 fonts" type="submit">Powtórki</button>
</div>
<div class="col-xs-10 col-xs-offset-2 col-sm-8 col-sm-offset-3 col-md-4 col-md-offset-0 col-lg-4 col-lg-offset-1">
<p class="fonts" style="font-size: 30px;">Co dzisiaj zrobisz aby osiągnąć swój cel?</p>
</div>
<div>
<button class="properbut btn btn-warning col-xs-10 col-xs-offset-2 col-sm-8 col-sm-offset-3 col-md-5 col-md-offset-0 col-lg-3 col-lg-offset-1 fonts" type="submit">Lekcje audio</button>
</div>
</div><!-- row -->
在firefox浏览器中按ctrl + shift + m来测试不同的屏幕。您可以看到它如何与列和偏移一起使用!
答案 3 :(得分:0)
我可以看到您正在使用vertical-align
属性。也可以尝试使用text-align: center
;
.row {
text-align: center;
}