[英]Vertical Centering in Twitter Bootstrap 3
I'm trying to figure out what is the best method in bootstrap 3 to align an element vertically. 我试图找出引导3中垂直对齐元素的最佳方法是什么。
I searched in the documentation and i didn't find any special class per the vertical align. 我在文档中进行了搜索,但每次垂直对齐都找不到任何特殊的类。
I would like that the text and the image are align vertically. 我希望文本和图像垂直对齐。 any idea?
任何想法?
This is my jsfiddle http://jsfiddle.net/ttfgL6ns/1/ 这是我的jsfiddle http://jsfiddle.net/ttfgL6ns/1/
<div class="container-fluid">
<div class="row">
<div class="scenes green">
<div class="col-xs-6 col-md-6">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do</div>
<div class="col-xs-6 col-md-6">
<img src="http://lorempixel.com/400/200" />
</div>
</div>
</div>
</div>
Moreover, it is more correct to add a div before or after the div with the class row ( <div class "row"
)? 而且,在具有类行的div之前或之后添加div更正确(
<div class "row"
)?
thanks 谢谢
using bootstrap you need to configure on DIV parent the height
before. 使用引导程序,您需要先在DIV父级上配置
height
。 After that, on DIV child, you use top:50%
like this: 之后,在DIV子级上,您使用
top:50%
像这样:
<div class="container-fluid">
<div class="row">
<div class="scenes green">
<div style="height:200px;">
<div class="col-xs-6 col-md-6" style="top: 50%;">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do</div>
<div class="col-xs-6 col-md-6">
<img src="http://lorempixel.com/400/200" />
</div>
</div>
</div>
</div>
I hope it help you. 希望对您有帮助。
in your case margin- and padding- of scenes and green classes should drive the alignment style. 在您的情况下,场景和绿色类的边距和填充应该驱动对齐方式。 the answer for better choice between before/after is irrelevant, "rows" just tells to the browser to render a responsive
<table><tr>
and all the children divs found with col- classes are splitted to responsive <td></td>
之前/之后之间更好选择的答案是无关紧要的,“行”只是告诉浏览器呈现一个响应式
<table><tr>
并且将所有通过col-类找到的子div拆分为响应式<td></td>
scenes and green styles before the class "row" apply the format to the same elements if declared after 如果在类“ row”之前声明了场景和绿色样式,则将格式应用于相同的元素
Try with vertical-align: middle property works only for display: table-cell; 尝试使用vertical-align:middle属性仅适用于显示:table-cell; element.
元件。 Second thing is vertical align works only for display:inline;
第二件事是垂直对齐仅适用于display:inline; elements.
元素。
<div class="container-fluid">
<div class="row">
<div class="scenes green">
<div class="col-xs-6 col-md-6">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do</div>
<div class="col-xs-6 col-md-6 display-table-cell">
<img src="http://lorempixel.com/400/200" />
</div>
</div>
</div>
</div>
and your css 和你的CSS
.display-table-cell {
display: table-cell;
vertical-allign: middle;
}
/* just to be sure img is inline */
.display-table-cell img {
display: inline;
}
You need to add class "col-md-12 col-xs-12" to father of class col-md-6 col-xs-6 Like this: 您需要将类“ col-md-12 col-xs-12”添加到类col-md-6 col-xs-6的父亲中,如下所示:
<div class="scenes green col-md-12 col-xs-12">
<div class="col-xs-6 col-md-6">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do</div>
<div class="col-xs-6 col-md-6">
<img src="http://lorempixel.com/400/200" />
</div>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.