简体   繁体   English

HTML Table THEAD元素背景颜色未四舍五入

[英]HTML Table THEAD Element Background color not rounding

I have the following HTML & CSS 我有以下HTML和CSS

HTML 的HTML

<table class="StandardTable">
    <thead>
        <tr>
            <th>A</th>
            <th>B</th>
            <th>C</th>
            <th>D</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td style="width: 25%">A</td>
            <td style="width: 25%">B</td>
            <td style="width: 25%">C</td>
            <td style="width: 25%">D</td>
        </tr>
    </tbody>
</table>

CSS 的CSS

.StandardTable {
    border: 1px solid #656565;
    border-radius: 10px;
    -moz-border-radius: 10px;
    margin-left: auto;
    margin-right: auto;
    box-shadow: 10px 10px 5px #888888;
    width: 300px;
    margin-bottom: 15px;
    border-spacing: 0;
}
.StandardTable thead {
    border-radius: 10px;
    -moz-border-radius: 10px;
    border-radius: 5px;
    background-color: lightgray;
}

I have created the jsFiddle for this too. 我也为此创建了jsFiddle The background in the THEAD always bleeds / runs out of the border and does not round. THEAD中的背景总是流血/超出边界且不会变圆。

I tested in IE, FF, and chrome. 我在IE,FF和chrome中进行了测试。 It is most apparent in chrome because the bleed happens above the border where in IE and FF the bleed happens under. 在chrome中最明显,因为出血发生在IE和FF下边界下方的边界上方。

Any help in fixing the issue (make the background stop correctly around the edges), is greatly appreciated. 非常感谢您提供解决问题的帮助(使背景正确停在边缘附近)。 I did try to add Border-Radius on TH element, but that did not work. 我确实尝试在TH元素上添加Border-Radius,但这没有用。

You need to apply the rounded corners to the first and last table cell in the thead. 您需要将圆角应用于thead中的第一个和最后一个表格单元。 Set the background for thead to transparent, and add this: 将thead的背景设置为透明,并添加以下内容:

.StandardTable thead th{
    background: lightgray; 
}

.StandardTable thead th:first-of-type{
    border-top-left-radius: 10px; 
}

.StandardTable thead th:last-of-type{
    border-top-right-radius: 10px; 
}

Demo JsFiddle 演示JsFiddle

try this (worked for me in FF) 试试这个(在FF为我工作)

.StandardTable {
    border: 1px solid #656565;
    border-radius: 10px;
    -moz-border-radius: 10px;
    margin-left: auto;
    margin-right: auto;
    box-shadow: 10px 10px 5px #888888;
    width: 300px;
    margin-bottom: 15px;
    border-spacing: 0;
}
.StandardTable thead tr th {
    background-color: lightgray;
}

.StandardTable thead tr th:first-child {
    z-index:-1;
    border-radius: 10px 0 0 0;
    -moz-border-radius: 10px 0 0 0;
    border-radius: 10px 0 0 0;
}
.StandardTable thead tr th:last-child {
    z-index:-1;
    border-radius: 0 10px 0 0;
    -moz-border-radius: 0 10px 0 0;
    border-radius: 0 10px 0 0;
}

Another workaround is to do the following 另一个解决方法是执行以下操作

.StandardTable {
    border: 1px solid #656565;
    border-radius: 10px;
    -moz-border-radius: 10px;
    margin-left: auto;
    margin-right: auto;
    box-shadow: 10px 10px 5px #888888;
    width: 300px;
    margin-bottom: 15px;
    border-spacing: 0;
    background-color: lightgray;
}
.StandardTable tbody tr td {
    background-color: white;
}

.StandardTable tbody tr:last-child td:last-child {
    border-bottom-right-radius: 10px;
}

.StandardTable tbody tr:last-child td:first-child {
    border-bottom-left-radius: 10px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM