简体   繁体   English

将div中的高度与左右浮动对齐

[英]Align height in divs with float left and right

I have a problem trying align a set of divs. 尝试对齐一组div时遇到问题。 I have this skeleton: 我有这个骨架:

<div>

    <div id="name1"></div>
    <div id="name2"></div>
    <div id="name3" class="little"></div>
    <div id="name4" class="little"></div>
    <div id="name5" class="little"></div>
    <div id="name6" class="little"></div>

</div>

I want that divs with "little" class float in the right, this works now, but I have two problems: 我希望那些带有“小”类的div在右边浮动,现在可以工作,但我有两个问题:

Right align problem: 右对齐问题: 正确对齐问题

Height align problem I need this height area the same for the three columns (name1, name2, others..) I can't add more containers because this is generated by the application. 高度对齐问题我需要这三个列的高度区域相同(name1,name2,其他..)我无法添加更多容器,因为这是由应用程序生成的。 It's posible that I have same hegiht in the three cases? 在这三种情况下,我有同样的意见吗? Height of the most taller (excluding "others" column when the content be too little) 最高的高度(当内容太少时不包括“其他”列)

Here a fiddle with the example: https://jsfiddle.net/fks86zq0/ 这里有一个小例子: https//jsfiddle.net/fks86zq0/

<div class="container">
<div id="name3" class="little">Hello world 1</div>
<div id="name4" class="little">Hello world 2</div>
<div id="name5" class="little">Hello world 2</div>
<div id="name6" class="little">Hello world 2</div>
</div>



.little{
  border: 1px solid #d2d2d2;
  border-radius: 4px;
  padding: 1.5em 0 0.2em;
  margin-bottom: 28px;
  width: 100%;
}
.container{
  width: 26.5%;  
  float:right;
}

One way is through CSS, ie using table-cell Property. 一种方法是通过CSS,即使用table-cell属性。 But for that to make it work, you need to remove float property. 但为了使它工作,你需要删除浮动属性。 I tried to do minimum changes to your existing code present on fiddle. 我试图对你小提琴上现有的代码做最小的改动。 Below is the code snippet. 以下是代码段。

HTML:- HTML: -

<div class= "row">
    <div id="name1" class="col">Lorem Ipsum es simplemente el texto de relleno de las imprentas y archivos de texto. Lorem Ipsum ha sido el texto de relleno estándar de las industrias desde el año 150</div>
    <div id="name2" class="col">Lorem Ipsum es simplemente el texto de relleno de las imprentas y archivos de texto. Lorem Ipsum ha sido el texto de relleno estándar de las industrias desde el año 1500, cuando un impresor (N. del T. persona que se dedica a la imprenta) desconocido usó una galería de textos y los mezcló de tal manera que logró hacer </div>
  <div class="col">
    <div id="name3" class="little">Hello world 1</div>
    <div id="name4" class="little">Hello world 2</div>
    <div id="name5" class="little">Hello world 2</div>
    <div id="name6" class="little">Hello world 2</div>
  </div>
</div>

CSS:- CSS: -

#name1, #name2 {
    border: 1px solid #a1c7e5;
    border-radius: 4px;
    padding: 0.5em 0 2.5em 0.5em;
    margin-right: 1.5em;
    width: 31%;
    position: relative;
}

.little{
    border: 1px solid #d2d2d2;
    border-radius: 4px;
    padding: 1.5em 1em 0.2em;
    margin-bottom: 28px;
    width: 26.5%;
}

.row {
  display: table;
}

.col {
   display: table-cell;
}

please used below .little class css. 请在下面使用.little class css。

.little {
   border: 1px solid #d2d2d2;
   border-radius: 4px;
   padding: 1.5em 0 0.2em;
   margin-bottom: 28px;
   float: right;
   width: 26.5%;
   clear: right;
}

see in https://jsfiddle.net/manish1226/fks86zq0/3/ 请参阅https://jsfiddle.net/manish1226/fks86zq0/3/

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

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