简体   繁体   English

HTML&CSS:div中两个高度相同的div

[英]HTML & CSS : same height two div in div

Firstly, excuse me for my bad english. 首先,请原谅我的英语不好。 But I have a problem with CSS. 但是我对CSS有问题。

I want to make the same height in color block in Div column. 我想在Div栏中的色块中设置相同的高度。

The block green is not the same height as the blue block. 绿色块与蓝色块的高度不同。 I want them to be at same height. 我希望他们身高相同。

The block : http://postimg.org/image/ej2jujnt1/ 区块: http : //postimg.org/image/ej2jujnt1/

<div class=cols>
    <div class="col col-1-3">
        <div class="bloc">
    </div>
    <div class="col col-2-3">
        <div class="bloc">
        </div>
        <div class="bloc">
        </div>
    </div>
</div>

.cols {
    position: relative;
    clear: both;
}

.cols > .col-1-3, .cols > .col-1-3 + .col-1-3 + .col-1-3 {
    width: 307px;
}

.cols > .col {
    float: left;
}

.cols > .col + .col {
    margin-left: 14px;
}

.cols > .col-2-3 {
    width: 629px;
}

.bloc {
    position: relative;
    z-index: 1;
    overflow: hidden;
    margin: 0px 0px 14px;
    box-shadow: 0px 2px 5px 1px #BFBFBF;
    border-radius: 3px 0px 0px;
    background-color: #FFF;
}

Is there any possible solution? 有没有可能的解决方案?

Thanks, 谢谢,

Vincent 文森特

I suggest you to use flexbox but it`s not supported by IE9 unfortunatelly 我建议您使用flexbox,但不幸的是IE9不支持它

The soultion is to add class for vertical column and style it like this: 灵魂是为垂直列添加类并为其设置样式:

* {
  box-sizing: border-box;
}
.bloc {
    position: relative;
    z-index: 1;
    width: 100%;
    overflow: hidden;
    box-shadow: 0px 2px 5px 1px #BFBFBF;
    border-radius: 3px 0px 0px;
    background-color: #FFF;
}

.cols {
  width: 80%;
  display: flex;
  margin: auto;
}
.col {
  display: flex;
  &.col-1-3 {
    flex: 1 1 33%;
    margin-right: 15px;
  }
  &.col-2-3 {
    flex: 1 1 66%;

  }
  &.col-vertical {
    display: flex;
    flex-direction: column;
    .bloc {
      display: flex;
      flex: 1 1 auto;
      margin-bottom: 15px;
      &:last-child {
        margin-bottom: 0;
      }
    }
  }
}

Here's codepen: http://codepen.io/insanepl/pen/doEKLz?editors=110 这是codepen: http ://codepen.io/insanepl/pen/doEKLz?editors=110

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

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