gpt4 book ai didi

html - 由于边框折叠属性,表格的边框半径不起作用

转载 作者:行者123 更新时间:2023-12-05 03:46:34 25 4
gpt4 key购买 nike

如果我在 table 标签上设置了 border-collapse 属性,我的边框半径不会显示。我需要 border-radius 属性,如果我删除 border-collapse 属性,我不会得到我想要的外观,即灰色部分会到达表格的最边缘。

解决这个问题的方法是什么,原因是什么?

提前致谢

* {
padding: 0;
margin: 0;
box-sizing: border-box;
}

table {
/*if i comment out the border-collapse property it then shows my radius*/
border-collapse: collapse;
margin: 25px 0;
width: 50%;
border-radius: 5px;
font-size: 1.4rem;
min-width: 400px;
border: 1px solid #c3c3c3;
/*margin is just for demo*/
margin: 20px 20px;
}

table tr {
border-bottom: solid 1px #d1d1d1;
}

table tr:nth-child(odd) {
background-color: #eee;
}

table td {
padding: 10px 15px;
}

table td:first-of-type {
font-weight: 600;
}
<table>
<tbody>
<tr>
<td>Application</td>
<td>Natural gas & LPG</td>
</tr>
<tr>
<td>Standards</td>
<td>BS EN ISO 9001:2008 - EN 331:1998</td>
</tr>
<tr>
<td>Connection</td>
<td>BSP Taper F</td>
</tr>
<tr>
<td>Finish</td>
<td>Plated</td>
</tr>
</tbody>
</table>

非常

最佳答案

如果您不想在内容背景和边框之间看到任何间距,则只需删除 border-collapse 并添加 border-spacing: 0border-spacing: 0 根本不会影响边框半径,它还会给你边框和内部内容之间没有空格的结果。

在搜索中,同时使用 collapse 和 radius 似乎有一些异常。还有一些解决方法,您可以在表格子项上使用伪标签,专门让半径起作用,但是当您可以使用 border-spacing 删除边框与其内部内容之间的空间时,为什么要浪费所有时间border-radius

配合良好

编辑: 通过将伪选择器与 border-space: 0 一起使用,您可以获得更明显的边框半径。

我们想要定位每个与表格元素边缘接壤的 td 元素。table tr td:first-of-typetable tr td:last of type 获取左侧和右侧。然后我们将每个后续的第一个和最后一个 child 作为目标来获得 Angular 落。最后,如果这是一个动态表,并且您将在表中放置超过 两个 数据表,请添加 td:not(:first-child):not(:last-child) 在每个类型的第一个和最后一个。

我没有得到我想要的外观,灰色部分一直延伸到表格的边缘。

* {
padding: 0;
margin: 0;
box-sizing: border-box;
}

table {
/*add border-spacing: 0 instead of border-collapse: collapse*/
border-spacing: 0;
margin: 25px 0;
width: 50%;
font-size: 1.4rem;
min-width: 400px;
/*margin is just for demo*/
margin: 20px 20px;
}


/* Start psuedo child tags here, targeting each data elements relevant corners and sides */

table tr td:first-of-type {
border-left: 1px solid #c3c3c3;
}

table tr td:last-of-type {
border-right: 1px solid #c3c3c3;
}

/* :not(:first-child):not(:last-child)
This will get any potential data tables that are added
that are not sides or corners however, they are border
data tables on top or bottom */

table tr:first-of-type td:not(:first-child):not(:last-child){
border-top: 1px solid #c3c3c3;
}


table tr:last-of-type td:not(:first-child):not(:last-child){
border-bottom: 1px solid #c3c3c3;
}

table tr:first-of-type td:first-child {
border-top: 1px solid #c3c3c3;
border-top-left-radius: 5px;
}

table tr:first-of-type td:last-child {
border-top: 1px solid #c3c3c3;
border-top-right-radius: 5px;
}

table tr:last-of-type td:last-child {
border-right: 1px solid #c3c3c3;
border-bottom: 1px solid #c3c3c3;
border-bottom-right-radius: 5px;
}

table tr:last-of-type td:first-child {
border-left: 1px solid #c3c3c3;
border-bottom: 1px solid #c3c3c3;
border-bottom-left-radius: 5px;
}

/* End Psuedo tags here */

table tr {
border-bottom: solid 1px #d1d1d1;
}

table tr:nth-child(odd) {
background-color: #eee;
}

table td {
padding: 10px 15px;
}

table td:first-of-type {
font-weight: 600;
}
<div id="table">
<table>
<tbody>
<tr>
<td>Application</td>
<td>here is some data</td>
<td>Natural gas & LPG</td>
</tr>
<tr>
<td>Standards</td>
<td>some data in between</td>
<td>BS EN ISO 9001:2008 - EN 331:1998</td>
</tr>
<tr>
<td>Connection</td>
<td>some data in between</td>
<td>BSP Taper F</td>
</tr>
<tr>
<td>more tables</td>
<td>some data in between</td>
<td>more data</td>
</tr>
<tr>
<td>some more data still</td>
<td>some data in between</td>
<td>and yet more about this data</td>
</tr>
<tr>
<td>Finish</td>
<td>Plated</td>
<td>Plated too</td>
</tr>
</tbody>
</table>
</div>

关于html - 由于边框折叠属性,表格的边框半径不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65238188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com