cell spacing in div table

I'd like the there to be 4 or so pixel space between each cell. I'd like the grey header to have the spaces rather then a block of grey. I tried playing around ( background-clip:padding-box; padding: 14px; margin etc) but couldn't figure out how to put a few pixels between cells in a div table. How do I do this?

Demo of problem http://jsfiddle.net/EJBnm/

<div class="TableBox">
    <div>
        <div>Head</div> <div>Bigger Head</div> <div>Medium</div>
    </div>
    <div>
        <div>First</div> <div>Second</div> <div>Third</div>
    </div>
    <div>
        <div>First</div> <div>Second</div> <div>Third</div>
    </div>
    <div>
        <div>First</div> <div>Second</div> <div>Third</div>
    </div>
</div>

css:

.TableBox {display: table;}
.TableBox > div {display: table-row; border-spacing: 5px}
.TableBox > div >div {display: table-cell;  margin: 4px;}
.TableBox > div:nth-child(even){ color: red; }
.TableBox > div:nth-child(1){  background-color: #666666; color:white; border-spacing: 15px; background-clip:padding-box; padding: 14px; margin:0 20px}

Add border-spacing: 4px; to your .TableBox class instead of your <tr>

Fiddle: http://jsfiddle.net/EJBnm/1/


您可以使用透明(或白色边框)代替边距:http://jsfiddle.net/jfsWc/

.TableBox > div >div {display: table-cell;  border:4px solid transparent}
链接地址: http://www.djcxy.com/p/94738.html

上一篇: 这些内联之间为什么会有无法解释的差距?

下一篇: 在div表中的单元格间距