gpt4 book ai didi

html - 具有 rowspan 的 TD 的高度大于内容(嵌套表): 1px diff in border placement of nested tables mimic the same row height of outer table

转载 作者:行者123 更新时间:2023-12-03 14:06:22 25 4
gpt4 key购买 nike

我有一个固定行高的外表(在本例中为 24px)。
我想嵌套一个表格来添加一些内容,但也想模仿里面的行高和边框。
但是这里有 1px 的差异:
enter image description here
我无法解释这一点,但感觉这与 rowspan 以及带有 flexbox 的嵌套表有关。
题:
我想知道innerTable 的预期高度为72px,但父td.itemblock 的高度为72.8px。
有人能告诉我这种差异的原因吗?是否有一些设置可以防止这种情况?

* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
}

table {
border-collapse: collapse;
box-sizing: border-box;
table-layout: fixed;
width: 100%;
font-size: 10px;
border-spacing: 0;
}

tr {
height: 24px;
}

td {
border-bottom: 1px solid black;
padding: 0;
vertical-align: top;
box-sizing: border-box;
}

.firstColumn {
width: 24px;
border-right: 1px solid black;
}

td.small {
width: 12px;
border-right: 1px solid black;
}

.title {
flex-grow: 1;
display: block;
text-overflow: ellipsis;
overflow: hidden;
height: 24px;
}

.item {
display: flex;
background-color: lightblue;
padding-left: 4px;
padding-right: 4px;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin-bottom: 1px;
height: 100%;
}

.innerTable td {
border-bottom: 0;
border-right: 0;
width: auto;
}

.itemCell {
position: relative;
}

.innerTable td.blockCell {
border-bottom: 1px solid black;
}
<html>

<head>
</head>

<body>

<table class="outerTable">
<tr>
<td rowspan="2" class="firstColumn">0</td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td rowspan="3" class="itemBlock">

<table class="innerTable">
<tr>
<td rowspan="3" class="itemCell">
<div class="item">
<div class="title">some content</div>
</div>
</td>
<td class="blockCell"></td>
</tr>
<tr>
<td class="itemCell blockCell">
<div class="item">
<div class="title">other content</div>
</div>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>


</td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td rowspan="2" class="firstColumn">1</td>
<td></td>
<td class="small"></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td rowspan="2" class="firstColumn">2</td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
</tr>
<tr>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>
<td></td>
<td class="small"></td>

</tr>

</table>
</body>
<html>

更新:
  • 它已确认在 Mac Chrome 和 Safari 中发生,可能也在其他浏览器中发生(使用 Run Code Snippet 检查结果)
  • 无论是否使用浏览器放大/缩小都会发生这种情况。

  • 根据建议,我能够组装它,看起来它正在工作。变化是:
  • 使用 box-shadows 而不是 border-bottom
  • 设置内表高度
  • 将元素 div 的高度设置为 calc(100% - 0.75px)

  • 虽然看起来我有一个“hacky”的解决方案,但我仍然没有解释!任何html表格专家?

    * {
    margin: 0;
    padding: 0;
    border: 0;
    outline: 0;
    }

    table {
    border-collapse: collapse;
    box-sizing: border-box;
    table-layout: fixed;
    width: 100%;
    font-size: 10px;
    border-spacing: 0;
    }

    tr {
    height: 24px;
    }

    td {
    box-shadow: 3px -3.5px 0px -3px rgba(0, 0, 0, 1) inset;
    padding: 0;
    vertical-align: top;
    box-sizing: border-box;
    }

    .firstColumn {
    width: 24px;
    border-right: 1px solid black;
    }

    td.small {
    width: 12px;
    border-right: 1px solid black;
    }

    .title {
    display: block;
    text-overflow: ellipsis;
    overflow: hidden;
    }

    .innerTable td {
    border-bottom: 0;
    border-right: 0;
    width: auto;
    height: 72px;
    }

    .itemCell {}

    .item {
    height: calc(100% - 0.75px);
    background: lightblue;
    display: flex;
    background-color: lightblue;
    padding-left: 4px;
    padding-right: 4px;
    }

    .innerTable td.blockCell {
    box-shadow: 3px -3.5px 0px -3px rgba(0, 0, 0, 1) inset;
    }
    <html>

    <head>
    </head>

    <body>

    <table class="outerTable">
    <tr>
    <td rowspan="2" class="firstColumn">0</td>
    <td></td>
    <td class="small"></td>
    <td></td>
    <td class="small"></td>
    <td></td>
    <td class="small"></td>
    </tr>
    <tr>
    <td></td>
    <td class="small"></td>
    <td rowspan="3" class="itemBlock">

    <table class="innerTable">
    <tr>
    <td rowspan="3" class="itemCell">
    <div class="item">
    <div class="title">some content</div>
    </div>
    </td>
    <td class="blockCell"></td>
    </tr>
    <tr>
    <td class="itemCell blockCell">
    <div class="item">
    <div class="title">other content</div>
    </div>
    </td>
    </tr>
    <tr>
    <td>
    </td>
    </tr>
    </table>


    </td>
    <td class="small"></td>
    <td></td>
    <td class="small"></td>
    </tr>
    <tr>
    <td rowspan="2" class="firstColumn">1</td>
    <td></td>
    <td class="small"></td>
    <td class="small"></td>
    <td></td>
    <td class="small"></td>
    </tr>
    <tr>
    <td></td>
    <td class="small"></td>
    <td class="small"></td>
    <td></td>
    <td class="small"></td>
    </tr>
    <tr>
    <td rowspan="2" class="firstColumn">2</td>
    <td></td>
    <td class="small"></td>
    <td></td>
    <td class="small"></td>
    <td></td>
    <td class="small"></td>
    </tr>
    <tr>
    <td></td>
    <td class="small"></td>
    <td></td>
    <td class="small"></td>
    <td></td>
    <td class="small"></td>

    </tr>

    </table>
    </body>
    <html>

    最佳答案

       

    table {
    border-collapse: collapse;
    box-sizing: border-box;
    table-layout: fixed;
    width: 100%;
    font-size: 10px;
    }

    tr {
    height: 24px;
    }



    td {

    box-shadow: 3px -3.5px 0px -3px rgba(0,0,0,1) inset;
    padding: 0;
    vertical-align: top;
    box-sizing: border-box;
    }

    .firstColumn {
    width: 24px;
    border-right: 1px solid black;
    }

    td.small {
    width: 12px;
    border-right: 1px solid black;
    }

    .title {
    flex-grow: 1;
    display: block;
    text-overflow: ellipsis;
    overflow: hidden;
    height: 24px;
    }

    .innerTable td {
    border-bottom: 0;
    border-right: 0;
    width: auto;
    }
    td.itemCell {
    background: lightblue;
    }
    .itemCell {
    position: relative;
    }

    .innerTable td.blockCell {
    box-shadow: 3px -3.5px 0px -3px rgba(0,0,0,1) inset;
    }
    <html>

    <head>
    </head>

    <body>

    <table class="outerTable">
    <tr>
    <td rowspan="2" class="firstColumn">0</td>
    <td></td>
    <td class="small"></td>
    <td></td>
    <td class="small"></td>
    <td></td>
    <td class="small"></td>
    </tr>
    <tr>
    <td></td>
    <td class="small"></td>
    <td rowspan="3" class="itemBlock">

    <table class="innerTable">
    <tr>
    <td rowspan="3" class="itemCell">
    <div class="item">
    <div class="title">some content</div>
    </div>
    </td>
    <td class="blockCell"></td>
    </tr>
    <tr>
    <td class="itemCell blockCell">
    <div class="item">
    <div class="title">other content</div>
    </div>
    </td>
    </tr>
    <tr>
    <td>
    </td>
    </tr>
    </table>


    </td>
    <td class="small"></td>
    <td></td>
    <td class="small"></td>
    </tr>
    <tr>
    <td rowspan="2" class="firstColumn">1</td>
    <td></td>
    <td class="small"></td>
    <td class="small"></td>
    <td></td>
    <td class="small"></td>
    </tr>
    <tr>
    <td></td>
    <td class="small"></td>
    <td class="small"></td>
    <td></td>
    <td class="small"></td>
    </tr>
    <tr>
    <td rowspan="2" class="firstColumn">2</td>
    <td></td>
    <td class="small"></td>
    <td></td>
    <td class="small"></td>
    <td></td>
    <td class="small"></td>
    </tr>
    <tr>
    <td></td>
    <td class="small"></td>
    <td></td>
    <td class="small"></td>
    <td></td>
    <td class="small"></td>

    </tr>

    </table>
    </body>
    <html>

    关于html - 具有 rowspan 的 TD 的高度大于内容(嵌套表): 1px diff in border placement of nested tables mimic the same row height of outer table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65039393/

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