html - 带div的表格边框间距

标签 html css

Table

你好,

我是 CSS 新手,我打算用 div(table-less)设计一个定价表。我使用下面的 css。我的主要问题是列和行之间的自定义空间。

当我添加“border-spacing”时,单元格的四个边会有边框。但是正如您在图片中看到的,我需要在单元格的每一侧留出不同的空间。

例如顶部和底部的边框间距为 0,左右边框间距为 10px。但我找不到任何解决方案。

CSS 样式:

.Table{
    display: table;
}
.Title{
    display: table-caption;
    text-align: center;
    font-weight: bold;
    font-size: larger;
}
.Heading{
    display: table-row;
    font-weight: bold;
    text-align: center;
}
.Row{
    display: table-row;
}
.Cell{
    display: table-cell;
    border: solid;
    border-width: thin;
    padding-left: 5px;
    padding-right: 5px;
    text-align: center;
}

.Full_width{
    width: 100%;
}

.No_border{
    border: none;
}

.mostpopular_tag{
    background-color:#F25050;
    color: #fff;
}

.pricing_table_header{
    line-height: 21px;
    background-color: #181818;
    color: #fff;
}

Table HTML 结构如下:

<div class="Table full_width">
    <div class="Row">
        <div class="Cell No_border">
            <p></p>
        </div>
        <div class="Cell No_border mostpopular_tag">
            <p>Most Popular</p>
        </div>
        <div class="Cell No_border">
            <p></p>
        </div>              
    </div>
    <div class="Heading ">
        <div class="Cell No_border pricing_table_header">
            <p>Heading 1</p>
        </div>
        <div class="Cell No_border pricing_table_header">
            <p>Heading 2</p>
        </div>
        <div class="Cell No_border pricing_table_header">
            <p>Heading 3</p>
        </div>
    </div>
    <div class="Row">
        <div class="Cell No_border">
            <p>Row 1 Column 1</p>
        </div>
        <div class="Cell No_border">
            <p>Row 1 Column 2</p>
        </div>
        <div class="Cell No_border">
            <p>Row 1 Column 3</p>
        </div>
    </div>
    <div class="Row">
        <div class="Cell No_border">
            <p>Row 2 Column 1</p>
        </div>
        <div class="Cell No_border">
            <p>Row 2 Column 2</p>
        </div>
        <div class="Cell No_border">
            <p>Row 2 Column 3</p>
        </div>
    </div>
</div>

这是我的表的演示:http://jsfiddle.net/2rFfL/

最佳答案

边框、边距和填充属性对于“全部”和“每一边”有不同的版本

所以,边框可以这样做:

border-width: 3px;

也可以这样写(第一个数在上,第二个在右,第三个在下,第四个在左):

border-width: 3px 5px 2px 10px;

或者,您可以像这样指定每一个:

border-top-width: 3px;
border-right-width: 5px;
border-bottom-width: 2px;
border-left-width: 10px;

关于html - 带div的表格边框间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25086239/

相关文章:

javascript - 当 phonegap 版本从 1.5 更新到 1.9 时,android 中的 Phonegap 应用程序导致强制关闭

jquery - IE9 中的 Max-Width 解决方案(带文本溢出)

html - 当 DIV 比其容器宽时,是否可能使 DIV 向左和向右溢出?

jquery - 在搜索功能中添加边距

c# - 如何以编程方式更改谷歌网站翻译器中的语言?

css - 移动 UI CSS 设计

CSS 不展开

javascript - 使用 javascript 通过文本字段更改段落

html - 如何确定在 Controller 操作中呈现哪个 View

c# - 网络核心 : Is it Possible to Merge TagBuilder Style Attributes with CSS Files?