[英]How to center align an inlined image in Bootstrap?
I have a drop down button and a responsive image in the same line with the below code. 我在以下代码的同一行中有一个下拉按钮和一个响应图像。
<div class="container dropdown ">
<a class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">
<span class="icon-bars-button">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</span>
</a>
<ul class="dropdown-menu">
<li><a href="#">Option1</a></li>
<li><a href="#">Option2</a></li>
<li><a href="#">Option3</a></li>
</ul>
<img class="img-responsive div-inline" src="res/test.png" alt="Logo">
</div>
CSS: CSS:
.div-inline{
display:inline-block;
}
The image gets displayed right next to drop down button. 图像将显示在下拉按钮旁边。 I want it to be in the center of the row. 我希望它位于行的中心。 Attached an image, the result is as in top of the image. 附加图像后,结果如图像顶部所示。 I want it as in the below portion of the image. 我想要它在图像的下面部分。
With bootstrap 3 you can add a class .center-block to center align 使用bootstrap 3,您可以添加一个类.center-block来居中对齐
<div class="container dropdown ">
<a class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">
<span class="icon-bars-button">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</span>
</a>
<ul class="dropdown-menu" >
<li ><a href="#">Option1</a></li>
<li ><a href="#">Option2</a></li>
<li ><a href="#">Option3</a></li>
</ul>
<img class="img-responsive div-inline center-block" src="res/test.png" alt="Logo">
</div>
You can do this placing a tag
in one div and img
in another div and define grid classes accordingly and add text-center
class to img
div. 您可以将a tag
放在一个div中,将img
放在另一个div中,并相应地定义网格类,然后将text-center
类添加到img
div中。
Alternatively, you can do this for you example. 或者,您可以为您的示例执行此操作。
.div-inline {
display: inline-block;
text-align: center;
width: 95%;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.