【问题标题】:Can not remove gray line between table head and body无法去除表头和表身之间的灰线
【发布时间】:2017-05-14 18:15:58
【问题描述】:

我正在 MVC 视图中生成一个表。代码很简单。

<div class="table-responsive">
    <table class="table table-hover">
        <thead>
        <tr>
            <th>
                Company Name
            </th>
            <th>
                Contact Name
            </th>
            <th>
                Contact Title
            </th>
            <th>
                Address
            </th>
            <th>
                City
            </th>
            <th>
                Region
            </th>
            <th>
                Country
            </th>
            @*<th></th>*@
        </tr>
        </thead>
        <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.CompanyName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.ContactName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.ContactTitle)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Address)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.City)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Region)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Country)
                </td>
            </tr>
        }
        </tbody>
    </table>
</div>

我正在使用引导程序,鉴于我编写了以下样式代码:

<style type="text/css">
    thead {
        background-color: #337aff;
        color: white;
        border-bottom-width: 0px;
    }

    tr:nth-child(even) {background-color: #f2f2f2}

    table {
        border: 2px solid #337aff;
        border-collapse: collapse;
        border-spacing: 0cm 0cm;
        font-family: verdana;
        border-bottom-width: 5px;
    }
    tbody {
        border-top-width: 0px;
    }
</style> 

问题是 theadtbody 之间以及两个 tr 之间有一条非常小的灰线,虽然我做了 border-collapse: collapse and border-spacing: 0cm 0cm;

我不知道为什么会这样,也许是 bootstrap.css 文件。

任何帮助都将被接受。

谢谢 帕萨

【问题讨论】:

    标签: html css asp.net-mvc twitter-bootstrap


    【解决方案1】:

    border-top”在“Bootstrap”本身的“tables.less”文件中设置为thead,tbody,tr和td,因此您可以使用删除微小的灰线"border: 0;" 在您的 CSS 中,如下所示:

    .table>tbody>tr>td, .table>tbody>tr>th,
    .table>tfoot>tr>td, .table>tfoot>tr>th,
    .table>thead>tr>td, .table>thead>tr>th
    {
      border: 0
    }
    

    完整代码:Remove tiny gray lines

    【讨论】:

    • 您也可以使用border-top: 0; 代替border: 0;,如果您只想删除两个“tr”之间的灰线,那么只需.table &gt; tbody &gt; tr &gt; td 即可工作并从您的CSS 文件中删除其他人
    • 工作!谢谢。
    猜你喜欢
    • 2019-03-11
    • 1970-01-01
    • 2017-01-02
    • 2023-01-26
    • 1970-01-01
    • 2021-04-18
    • 2022-01-01
    • 2010-09-13
    • 1970-01-01
    相关资源
    最近更新 更多