gpt4 book ai didi

html - 如何为 html tr 添加边框

转载 作者:太空宇宙 更新时间:2023-11-03 20:01:02 25 4
gpt4 key购买 nike

假设我定义了这样一个表

1    Chailie     23  Joker   Bass
2 Chailie 23 Joker Bass
3 Chailie 23 Joker Bass
4 Chailie 23 Joker Bass
5 Chailie 23 Joker Bass
6 Chailie 23 Joker Bass

现在我想让它看起来像这样

|----------------------------------------|
|1 Chailie 23 Joker Bass |
|2 Chailie 23 Joker Bass |
|3 Chailie 23 Joker Bass |
|----------------------------------------|
|4 Chailie 23 Joker Bass |
|5 Chailie 23 Joker Bass |
|6 Chailie 23 Joker Bass |
|----------------------------------------|

如你所见,我想为 tr 的一部分添加边框并使其看起来像被分组,有人知道如何实现吗?例如,我可以添加一些 CSS 来设置这样的边框吗?

最佳答案

尝试 :nth-child CSS 属性

tr:nth-child(3n+0) {
background-color: lime;
}
tr:nth-child(3n+0) td {
border-top :1px dashed blue;
}

Working DEMO

更多更新阅读您的评论后,试试这个

tr:nth-child(3n+1) td {
border-top : 1px dashed blue;
}
td:first-child {
border-left : 1px dashed blue;
}
td:last-child {
border-right : 1px dashed blue;
}

Working DEMO

替代方式:(兼容跨浏览器)

tr:nth-child(3n+1) td {
border-top : 1px solid grey;
}
table {
border-right:1px solid grey;
border-left: 1px solid grey;
}

alternative method DEMO

关于html - 如何为 html tr 添加边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16475846/

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