Table cells height calculated differenly in IE11

隐身守侯 提交于 2019-11-29 09:37:26

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>

I will just add margin to total 100

.tall {
  height: 100px;
}

.medium {
  height: 60px;
  margin: 20px 0;
}

.short {
  height: 30px;
  margin: 35px 0;
}

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!