Table cells height calculated differenly in IE11

后端 未结 3 653
独厮守ぢ
独厮守ぢ 2020-12-19 02:31

The problem I face is IE 11 seem to have inconsistent inner height across single while other browsers keep it the sa

相关标签:
3条回答
  • 2020-12-19 02:53

    I finally managed to do that. Here is the code, hope it helps. Fiddle here.

    var spans = document.querySelectorAll( "span.bar" ),
    count = spans.length;
    while ( count-- ) {
       spans[count].style.height = spans[count].parentElement.offsetHeight + "px";
    }
        
    body {
        padding:15px;
    }
    table {
        border: 1px solid black;
        border-spacing: 10px;
        cell-spacing: 0;    
    }
    
    tr {
        border: 1px solid red;
    }
    
    td {
        vertical-align:center;
        position:relative;
        box-sizing: border-box;
        position: relative;
        border: 1px solid black;
    }
    
    td .bar:first-child,
    td .bar:last-child {
        display: block;
        background: green;
        width: 3px; 
        left: -5px;
        height: 100%;
        position: absolute; top: 0; 
        z-index: 1;
    }
    
    p {
        margin: 0;
        background-color: #dedede;
        padding: 0px;
    }
    
    .tall {
        height: 100px;
    }
    
    .medium {
        height: 60px;
    }
    
    .short {
        height: 30px;
    }
    <table cellspacing="1" cellpadding "0" border="0">
        <tr>
            <td>
                <span class="bar"></span><p class="tall">Save me!</p><span class="bar"></span>
            </td>
            <td>
                <span class="bar"></span><p class="medium">From problems</p><span class="bar"></span>
            </td>
            <td>
                <span class="bar"></span><p class="short">With IE</p><span class="bar"></span>
            </td>
        </tr>
    </table>

    0 讨论(0)
  • 2020-12-19 02:53

    Strange and interesting behavior by IE about table-cell here. If you want an approach, you should put the cell on inline-block and set the height value, then align the content using line-height also reset the line-height for the text container like:

    td {
      display: inline-block;
      height: 137px;
      position: relative;
      line-height: 137px;
    }
    
    p {
      display: inline-block;
      vertical-align: middle;
      background-color: #dedede;
      line-height: 1;
    }
    

    Try on IE, I hope this will help you: http://codepen.io/pik_at/pen/WbyZrG

    0 讨论(0)
  • 2020-12-19 03:04

    I will just add margin to total 100

    .tall {
      height: 100px;
    }
    
    .medium {
      height: 60px;
      margin: 20px 0;
    }
    
    .short {
      height: 30px;
      margin: 35px 0;
    }
    
    0 讨论(0)
提交回复
热议问题