gpt4 book ai didi

html - CSS - 表格单元格边距?

转载 作者:太空宇宙 更新时间:2023-11-04 07:28:15 24 4
gpt4 key购买 nike

我以为这很容易,但我卡住了

https://codepen.io/anon/pen/JLaqWw

表格的左侧我需要在 tr 的左侧留一个边距,但标题下的线需要转到表格的边缘。

enter image description here

在我的示例中,我通过在线上方和下方放置一个 20px 宽度的 div 来完成此操作。

我显然不能这样做,但我不知道应该怎么做。

body{
background: grey;
font-family: sans-serif;
}
.page{
background: white;
width: 1200px;
margin: 0 auto;
}
.table-con{
overflow: scroll;
max-width: 1200px;
}

.white-block{
width: 10px;
height: 150px;
background: white;
position: absolute;
top: 50px;
}

.white-block-1{
height: 20px;
top: 20px;
}


table{
/*table-layout: fixed;*/
border-collapse: collapse;
width: 1500px;
}

thead th{
text-align: left;
}

thead tr{
border-bottom: 1px solid #444;
}

tbody tr{
border-bottom: 1px solid #aaa;
}

tbody tr:nth-child(even){
background: yellow;
}

th, td{
padding: 10px 5px;

&:first-of-type{
padding-left: 20px;
}

&:last-of-type{
padding-right: 20px;
}
}

最佳答案

在 CSS 中总是有大量的方法可以达到任何想要的效果。在你的情况下,我现在能想到的最简单的方法就是添加额外的列作为左边距。

我已经修改了你的 fiddle 并成功实现了你想要的:
https://codepen.io/anon/pen/KoxEvb

我添加了额外的列并更改了它的样式。请注意,我已将背景色从 tr 移至 td。我一直发现 tr 样式依赖于浏览器,所以我尽可能避免使用它。

此外,还有一些必须解决的特殊问题,有关更多信息,请阅读:
https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity

关于html - CSS - 表格单元格边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49670162/

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