简体   繁体   English

自动兄弟div中的CSS高度100%在Chrome中不起作用

[英]CSS height 100% in automatic brother div not working in Chrome

Can't fixed it... 无法修复...

I have a div with 2 divs inside. 我有一个div,里面有2个div。 The first one determinates height and the second one takes that height. 第一个确定高度,第二个确定该高度。 But chrome don't want to do it. 但是Chrome不想这么做。

<div style="display: table; height: 100%; width: 100%; min-height: 100%;">
    <div FIRST-DIV-HEIGHT-VARIABLE WITH FLOAT LEFT></div>

    <div style="box-sizing: border-box; display: table; float: right; 
    height: auto; min-height: 100%; padding: 0 20px 81px; position: relative; 
    width: 280px; -moz-box-sizing: border-box; -ms-box-sizing: border-box; 
    -webkit-box-sizing: border-box; -khtml-box-sizing: border-box; 
    -o-box-sizing: border-box;"></div>
</div>

Add display:table-cell property for your child div. 为您的孩子div添加display:table-cell属性。 So that automatically adjust the height of sibling divs. 这样可以自动调整同级div的高度。

 <div style="display:table; width:100%; height:100%; border:1px solid #f000ff;">
    <div style="height:400px; display:table-cell; background-color:#ff000f;">My Main Content</div>
    <div style="display:table-cell; float:right; height:100%; background-color:#ff00ff;">My Sample Content</div>
</div>

Check the Working JSFIDDLE HERE 这里检查工作的JSFIDDLE

In the above fiddle I have assigned the first child div height as 400px. 在上面的小提琴中,我已将第一个子div高度指定为400px。 If you modify this height, the right side div automatically adjust its height. 如果您修改此高度,则右侧div会自动调整其高度。 Check it out and let me know if any issues. 检查一下,让我知道是否有任何问题。

Flexboxes are the easiest way to create columns of equal height: Flexbox是创建等高列的最简单方法:

<style>
  .container {
    display: flex;
    display: -mx-flexbox; // IE10
    display: -webkit-flex; // Safari
    flex-grow: 0;
    -ms-flex-grow: 0; // IE10
    -webkit-flex-grow: 0; // Safari
  }
  .left, .right { width: 50%; }
  .left { 
    background-color: #c66; 
    height: 200px;
  }
  .right { background-color: #66c; }
</style>


<div class="container">
  <div class="left">
    <p>This is the left DIV.</p>
  </div>
  <div class="right">
    <p>This is the right DIV.</p>
    <p>Its height is equal to the left DIV.</p>
  </div>
</div>

Flexboxes do not work in IE9 and older. Flexbox在IE9及更低版本中不起作用。 Suresh idea above works in older browsers, but there is a mistake in the code (table cells don't float) and inline CSS is better avoided: 上面的Suresh想法适用于较旧的浏览器,但是代码中有一个错误(表单元格不浮动),最好避免使用内联CSS:

<style>
  .container { display: table; }
  .row { display: table-row; }
  .left, .right { 
    display: table-cell;
    width: 50%; 
  }
  .left { 
    background-color: #c66; 
    height: 200px;
  }
  .right { background-color: #66c; }
</style>


<div class="container">
  <div class="row">
    <div class="left">
      <p>This is the left DIV.</p>
    </div>
    <div class="right">
      <p>This is the right DIV.</p>
      <p>Its height is equal to the left DIV.</p>
    </div>
  </div>
</div>

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

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