2017-06-15 118 views
1

我想要一个带有表格单元格的css表格,在其左侧有一个边框(请参阅小提琴)。它通过绝对定位并在Chrome中使用顶部和底部值。 但在IE11(和更老的我猜)边界根本没有显示。什么是实现这一目标的最佳解决方案,并使其可在所有浏览器(低至IE9)下工作? https://jsfiddle.net/jhparj52/7/在IE11的表格单元格的顶部和底部填充有边框

HTML:

<div class="the-table"> 
    <div class="cell-containing-border"> 
     <div class="the-border"></div> 
    <div> 
</div> 
</div> 
    <div class="cell-not-containing-border"></div> 
</div> 

CSS:

.the-table { 
    display: table; 
    height: 80px; 
    background-color: red; 
    width: 80px; 
} 

.cell-containing-border { 
    display:table-cell; 
    position: relative; 
} 

.the-border { 
    top: 10px; 
    bottom: 10px; 
    position: absolute; 
    border-left: 4px solid black; 
} 

.cell-not-containing-border { 
    display: table-cell; 
    height: 40px; 
} 

回答

1

添加填充似乎解决该问题:

.the-table { 
 
    display: table; 
 
    height: 80px; 
 
    background-color: red; 
 
    width: 80px; 
 
} 
 

 
.cell-containing-border { 
 
    display: table-cell; 
 
    position: relative; 
 
} 
 

 
.the-border { 
 
    top: 10px; 
 
    bottom: 10px; 
 
    position: absolute; 
 
    border-left: 4px solid black; 
 
    padding: 20px 0px 20px 0; 
 
} 
 

 
.cell-not-containing-border { 
 
    display: table-cell; 
 
    height: 40px; 
 
}
<div class="the-table"> 
 
    <div class="cell-containing-border"> 
 
    <div class="the-border"> 
 

 
    </div> 
 
    <div> 
 

 
    </div> 
 
    </div> 
 
    <div class="cell-not-containing-border"> 
 

 
    </div> 
 
</div>

+0

这似乎没有边界垂直对齐到中间,因为它为顶部/底部10px的。 – Mike

+0

这与明确设定高度的权利是一样的吗? – Mike

0

我能找到的唯一解决方案是设置一个明确的边界高度。对于父级的固定高度,可以计算高度以获得顶部和底部的相同填充。

.the-table { 
 
    display: table; 
 
    height: 80px; 
 
    background-color: red; 
 
    width: 80px; 
 
} 
 
    
 
.cell-containing-border { 
 
    display:table-cell; 
 
    position: relative; 
 
} 
 
    
 
.the-border { 
 
    top: 10px; 
 
    position: absolute; 
 
    border-left: 4px solid black; 
 
    height: 60px; 
 
} 
 
    
 
.cell-not-containing-border { 
 
    display: table-cell; 
 
    height: 40px; 
 
}
<div class="the-table"> 
 
    <div class="cell-containing-border"> 
 
    <div class="the-border"></div> 
 
    <div></div> 
 
    </div> 
 
    <div class="cell-not-containing-border"></div> 
 
</div>

相关问题