简体   繁体   English

如何使div行中的所有元素底部对齐?

[英]How to bottom align all elements within the div row?

I have a row made up of four columns. 我有一排由四列组成。 Each column contains 3 things center aligned: text output, a label and an image. 每列包含3个居中对齐的内容:文本输出,标签和图像。 The images are sized differently so the alignment is off. 图像的大小不同,因此对齐不正确。 I want to align all elements in each column to the bottom for consistency across the row. 我想将每列中的所有元素都对齐到底部,以确保行的一致性。

I've tried 我试过了

style="text-align:bottom;" bottom:0, vertical-align:bottom;"

and nothing seems to make a difference. 似乎没有什么改变。

奇特的对齐图片在这里

My code is: 我的代码是:

<div class="row">
    <div class="col-xs-12">
        <div class="col-xs-6 col-md-2">
            <div align="center"><img src="@Url.Content("random.png")" /></div>
            <div id="Text1" class="text-center">1</div>
            <div class="text-center">Label1</div>
        </div>
        <div class="col-xs-6 col-md-2 col-md-offset-1">
            <div align="center"><img  src="@Url.Content("random2.png")" /></div>
            <div id="text2" class="text-center">2</div>
            <div class="text-center">Label2</div>
        </div>
        <div class="col-xs-6 col-md-2 col-md-offset-1">
            <div align="center"><img  src="@Url.Content("random3.png")" /></div>
            <div id="text3" class="text-center">3</div>
            <div class="text-center">Label3</div>
        </div>
        <div class="col-xs-6 col-md-2 col-md-offset-1">
            <div align="center"><img  src="@Url.Content("random.png")" /></div>
            <div id="text2" class="text-center">3.4</div>
            <div class="text-center">Label</div>
        </div>
    </div>
</div>

Also, I was told padding would influence how bootstrap aligns content in different displays. 另外,我被告知填充会影响引导程序如何在不同的显示器中对齐内容。 Any suggestions? 有什么建议么?

Thanks, in advance 提前致谢

You can achieve the same layout with fewer classes and wrappers, and not have padding issues. 您可以使用更少的类和包装器来实现相同的布局,并且不会出现填充问题。 When you nest columns inside columns they have to be surrounded by a .row in all cases otherwise you get double gutter problems on the outer edges. 当您将列嵌套在列中时,在所有情况下必须用.row包围,否则在外边缘会出现双槽问题。 And outside of all of that there must be a .container-fluid or a .container to adjust the negative margin on the L and R of the .row. 和所有的外部必须有一个.container-流体或.container调整在.row的L和R的负幅度。 You don't nest .container/.container-fluid 您不嵌套.container / .container-fluid

Here's a revised version. 这是修订版。 Try it out. 试试看。

DEMO: http://jsbin.com/huhamu/1/ 演示: http : //jsbin.com/huhamu/1/

Notice that when you use inline-block on .col-xs-6 in this case you have to remove the spaces created by the display:inline/inline-block style. 请注意,在这种情况下,当在.col-xs-6上使用inline-block时,必须删除display:inline / inline-block样式创建的空格。 This can be done by formatting your html as follows with the comments as they are (or you can zero out the font size on the parent and apply it on the children): 这可以通过按如下所示格式化HTML并带有注释来实现(或者您可以将父字体的字体大小归零,然后将其应用于子字体):

<div class="container">
   <div class="row inline-block-row text-center">
      <div class="col-xs-6 col-md-3">
         <img src="@Url.Content("random.png")" />
         <div id="Text1">1</div>
         Label1
      </div><!--comment
--><div class="col-xs-6 col-md-3">
         <img  src="@Url.Content("random2.png")" />
         <div id="text2" class="text-center">2</div>
         Label2 this is a test
      </div><!--comment
--><div class="col-xs-6 col-md-3">
         <img  src="@Url.Content("random3.png")" />
         <div id="text3" class="text-center">3</div>
         Label3
      </div><!--comment
--><div class="col-xs-6 col-md-3">
         <img  src="@Url.Content("random.png")" />
         <div id="text2">3.4</div>
         Label
      </div>
   </div>
</div>  

CSS: CSS:

.inline-block-row .col-xs-6 {
  border:1px solid red;
  float:none;
  display:inline-block; /* the default is baseline, so no need to add vertical alignment in your case*/
}

IMAGES: 图片:

If you have images that will be bigger -- at any size of your viewport -- than the viewport, put the following classes on them to make them responsive and to center it. 如果在任何视口大小下具有比视口更大的图像,请在其上放置以下类,以使它们响应并居中。

<img src="myimage.png" class="img-responsive center-block" alt="" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM