height: 100% for
inside
with display: table-cell

后端 未结 7 1418
醉话见心
醉话见心 2020-11-29 21:44

Here is 2 column markup using display: table and display: table-cell CSS declarations:

相关标签:
7条回答
  • 2020-11-29 22:23

    In Addition to jsFiddle, I can offer an ugly hack if you wish in order to make it cross-browser (IE11, Chrome, Firefox).

    Instead of height:100%;, put height:1em; on the .cell.

    0 讨论(0)
  • 2020-11-29 22:25

    When you use % for setting heights or widths, always set the widths/heights of parent elements as well:

    .table {
        display: table;
        height: 100%;
    }
    
    .cell {
        border: 2px solid black;
        vertical-align: top;
        display: table-cell;
        height: 100%;
    }
    
    .container {
        height: 100%;
        border: 2px solid green;
        -moz-box-sizing: border-box;
    }
    <div class="table">
        <div class="cell">
            <p>Text
            <p>Text
            <p>Text
            <p>Text
            <p>Text
            <p>Text
            <p>Text
            <p>Text
        </div>
        <div class="cell">
            <div class="container">Text</div>
        </div>
    </div>

    0 讨论(0)
  • 2020-11-29 22:26

    set height: 100%; and overflow:auto; for div inside .cell

    0 讨论(0)
  • 2020-11-29 22:38

    Make the the table-cell position relative, then make the inner div position absolute, with top/right/bottom/left all set to 0px.

    .table-cell {
      display: table-cell;
      position: relative;
    }
    
    .inner-div {
      position: absolute;
      top: 0px;
      right: 0px;
      bottom: 0px;
      left: 0px;
    }
    
    0 讨论(0)
  • 2020-11-29 22:40
    table{
       height:1px;
    }
    
    table > td{
       height:100%;
    }
    
    table > td > .inner{
       height:100%;
    }
    

    Confirmed working on:

    • Chrome 60.0.3112.113, 63.0.3239.84
    • Firefox 55.0.3, 57.0.1
    • Internet Explorer 11
    0 讨论(0)
  • 2020-11-29 22:47

    This is exactly what you want:

    HTML

    <div class="table">
    
        <div class="cell">
            <p>Text</p>
            <p>Text</p>
            <p>Text</p>
            <p>Text</p>
            <p>Text</p>
            <p>Text</p>
            <p>Text</p>
            <p>Text</p>
        </div>
        <div class="cell">
            <div class="container">Text</div>
        </div>
    </div>
    

    CSS

    .table {
        display: table;
        height:auto;
    }
    
    .cell {
        border: 2px solid black; 
        display:table-cell;
        vertical-align:top;
    }
    
    .container {
        height: 100%;
        overflow:auto;
        border: 2px solid green;
        -moz-box-sizing: border-box;
    }
    
    0 讨论(0)
提交回复
热议问题