我想防止绿色框在水平滚动后通过边界显示.必须有白色边框,并且必须使用桌子.除非绝对必要,否则最好不要使用JavaScript.

    .container {
        overflow-x: auto;
        width: 250px;
    }

    table {
        border-collapse: collapse;
    }

    td {
      padding: 10px;
    }

    th {
        background-color: red;
        color: white;
        padding: 10px;
        position: relative;
    }

    tr {
      border-bottom: 1px solid white; 
    }

    .sticky {
        background-color: blue;
        color: white;
        position: sticky;
        z-index: 2;
    }

    .sticky::before {
        content: "";
        position: absolute;
        top: 0;
        right: 0;
        width: 2px;
        height: 100%;
        background-color: white;
    }

    .test1 {
        left: 0;
    }

    .test2 {
        left: 55.86px;
    }

    .test3 {
        left: calc(55.86px * 2);
    }

    .popover-container {
      position: relative
    }

    .popover {
      background-color: green;
      color: white;
      height: 40px;
      position: absolute;
      top: 10px;
      left: -12px;
      z-index: 1;
    }
 <div class="container">
        <table>
            <thead>
                <tr>
                    <th class="sticky test1">
                        Test1
                    </th>
                    <th class="sticky test2">
                        Test2
                    </th>
                    <th class="sticky test3">
                        Test3
                    </th>
                    <th>
                        Test4
                    </th>
                    <th>
                        Test5
                    </th>
                    <th>
                        Test6
                    </th>
                </tr>
            </thead>
            <tbody>
              <tr>
                <td class="sticky test1">
                test1
                </td>
                <td class="sticky test2">
                test2
                </td>
                <td class="sticky test3">
                test3
                </td>
                <td>
                test4
                </td>
                <td>
                test5
                </td>
                <td>
                test6
                </td>
              </tr>
              <tr>
                <td class="sticky test1">
                test1
                </td>
                <td class="sticky test2">
                test2
                </td>
                <td class="sticky test3">
                test3
                </td>
                 <td>
                test4
                </td>
                <td>
                  <div class="popover-container">
                    test5
                    <div class="popover">
                      popover
                    </div>
                  </div>
                </td>
                <td>
                test6
                </td>
              </tr>
              <tr>
                <td class="sticky test1">
                test1
                </td>
                <td class="sticky test2">
                test2
                </td>
                <td class="sticky test3">
                test3
                </td>
                <td>
                test4
                </td>
                <td>
                test5
                </td>
                <td>
                test6
                </td>
              </tr>
            </tbody>
        </table>
    </div>

我想防止绿色框在水平滚动后通过边界显示.必须有白色边框,并且必须使用桌子.除非绝对必要,否则最好不要使用JavaScript.

推荐答案

您可以创建一个伪元素来填补空白:

.container {
        overflow-x: auto;
        width: 250px;
    }

    table {
        border-collapse: collapse;
    }

    td {
      padding: 10px;
    }

    th {
        background-color: red;
        color: white;
        padding: 10px;
        position: relative;
    }

    tr {
      border-bottom: 1px solid white; 
    }

    .sticky {
        background-color: blue;
        color: white;
        position: sticky;
        z-index: 2;
    }

    .sticky::before {
        content: "";
        position: absolute;
        top: 0;
        right: 0;
        width: 2px;
        height: 100%;
        background-color: white;
    }
    .sticky::after {
        content: "";
        position: absolute;
        bottom: -4px;
        left: 0;
        height: 4px;
        width: 100%;
        background-color: yellow;
    }

    .test1 {
        left: 0;
    }

    .test2 {
        left: 55.86px;
    }

    .test3 {
        left: calc(55.86px * 2);
    }

    .popover-container {
      position: relative
    }

    .popover {
      background-color: green;
      color: white;
      height: 40px;
      position: absolute;
      top: 10px;
      left: -12px;
      z-index: 1;
    }
<div class="container">
        <table>
            <thead>
                <tr>
                    <th class="sticky test1">
                        Test1
                    </th>
                    <th class="sticky test2">
                        Test2
                    </th>
                    <th class="sticky test3">
                        Test3
                    </th>
                    <th>
                        Test4
                    </th>
                    <th>
                        Test5
                    </th>
                    <th>
                        Test6
                    </th>
                </tr>
            </thead>
            <tbody>
              <tr>
                <td class="sticky test1">
                test1
                </td>
                <td class="sticky test2">
                test2
                </td>
                <td class="sticky test3">
                test3
                </td>
                <td>
                test4
                </td>
                <td>
                test5
                </td>
                <td>
                test6
                </td>
              </tr>
              <tr>
                <td class="sticky test1">
                test1
                </td>
                <td class="sticky test2">
                test2
                </td>
                <td class="sticky test3">
                test3
                </td>
                 <td>
                test4
                </td>
                <td>
                  <div class="popover-container">
                    test5
                    <div class="popover">
                      popover
                    </div>
                  </div>
                </td>
                <td>
                test6
                </td>
              </tr>
              <tr>
                <td class="sticky test1">
                test1
                </td>
                <td class="sticky test2">
                test2
                </td>
                <td class="sticky test3">
                test3
                </td>
                <td>
                test4
                </td>
                <td>
                test5
                </td>
                <td>
                test6
                </td>
              </tr>
            </tbody>
        </table>
    </div>

Html相关问答推荐

从收件箱获取内部HTML值

为什么在Vuettify 3中使用Flex时会忽略宽度?

损坏的可点击html邮箱签名

创建一个带有div和径向渐变的全宽半圆

小虫?CSS Flexbox间隙应用于两个内联文本块之间,因为它们之间存在绝对定位的元素

布局更改时的转换

`table>;的消失;tbody:nth子级(1)`HTML

如何在悬停时使用 CSS 更改许多同级元素

如何为高度较小的块制作边框动画?

如何在悬停时使矩形按钮上的边框变圆

为什么 CSS 网格超出了父级?

将三个div转换为显示flex

如何在 VS Code 中 Select 和删除 HTML 元素(其标签和内容)?

排列卡片时遇到困难

带圆角帽的 CSS 部分边框

在Firefox中使用keySplines时,SVG: <animateMotion>不起作用

如何垂直平移一个元素,使其新位置位于另外两个元素之间?

为什么在使用src与srcdoc时 iframe 内容高度呈现不同?

在不扭曲图像的情况下将图像放入灵活的 Div 框内

CSS:如何在模糊的背景上剪切文本?