防止带有边框折叠的表的缩进,分开

时间:2015-06-12 18:31:33

标签: html css css3 border-spacing

我有一些非常基本的HTML:

    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
<table>
    <tr>
        <th>Addressed to</th>
        <th>Sender</th>
        <th>Price</th>
        <th>Comments</th>
    </tr>
    <tr>
        <td>Joe smith</td>
        <td>Ralph Lauren</td>
        <td>$200</td>
        <td>Lorem ipsum dolor sit amer</td>
    </tr>
    <tr>
        <td>Joe smith</td>
        <td>Ralph Lauren</td>
        <td>$200</td>
        <td>Lorem ipsum dolor sit amer</td>
    </tr>
</table>
<p>It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>

现在,我想在表格行和列之间添加间距,所以我添加了这个css:

table {
border-collapse: separate;
border-spacing: 20px 10px;
}

大。除了现在表格本身不再用2段落后。

enter image description here

我的问题是表格如何获得所需的间距而不是缩进,或者如何应用最少的CSS来克服缩进?

http://jsfiddle.net/smlombardi/9mzzdsrn/1/

上查看此代码

3 个答案:

答案 0 :(得分:2)

对于快速解决方案(特别是如果它是一个静态网站),只需将边距缩回20px(与桌面上的缩进相同)

margin-left:-20px;

here是一个有效的例子

答案 1 :(得分:0)

除了使用border-spacing之外,你可以只设置表格上的边距,然后还为每一行设置填充,以达到与左侧文本冲洗相同的效果

table {
    border-collapse: separate;
    margin-right:20px;
}
td {
    padding-top:10px;
}

答案 2 :(得分:0)

table {
    border-collapse: separate;
    margin-right:20px;
}
td {
    padding:10px;
}