html 和 css 表格与 tr 和 td 重叠边框

标签 html css

我有一个带边框的表格,我想让表格保持可滚动。

表格中的行有一个底部边框。我想要的是有两个重叠边框,但除非添加另一行,否则不会导致滚动条出现。

制作最后一个<td>没有边框将不起作用,因为行是动态的,可以添加或删除它们。

东西 like this ,但除非有另一行,否则不会出现滚动条。

我希望它看起来是like this ,但是当有新行时,它会滚动,但会添加一个 overflow:scroll 到表,在没有新行时创建滚动条。

<div class="table-wrapper" style="height:272px;border: solid 1px #CCC;">
<table>
<tbody>
 <tr>
 <td>
     stackoverflow 
 </td>
 </tr>
  <tr>
   <td>
     stackoverflow 
 </td>
 </tr>
  <tr>
    <td>
     stackoverflow 
 </td>
 </tr>
  <tr>
     <td>
     stackoverflow 
 </td>
 </tr>
  <tr>
     <td>
     stackoverflow 
 </td>
 </tr>
</tbody>
</table>
</div>

tbody{
  width:100%;
}
td{
  height:50px;
  border-bottom:solid 1px #CCC;
  width:100%;
}
tr{
  width:100%;
}
.table-wrapper{
  overflow:auto;
}
table{
  width:100%;
}

最佳答案

我认为您正在寻找这样的东西:

.table-wrapper {
    overflow : hidden;
    height : 300px;
}

.table-wrapper, table {
    height : 300px;
}

.table-wrapper, td {
    border : solid 1px #CCC;
}

table, tbody, tr, td {
    box-sizing: border-box;
    display: block;
}

table {
    margin: 1px 0 0 0;
    overflow : auto;
}

td {
    height: 60px;
    border-width : 0 0 1px 0;
}
<div class="table-wrapper">
    <table>
        <tbody>
             <tr>
                 <td>stackoverflow</td>
             </tr>
              <tr>
                 <td>stackoverflow</td>
             </tr>
              <tr>
                 <td>stackoverflow</td>
             </tr>
              <tr>
                 <td>stackoverflow</td>
             </tr>
              <tr>
                 <td>stackoverflow</td>
             </tr>
        </tbody>
    </table>
</div>

(另见 this Fiddle)

关于html 和 css 表格与 tr 和 td 重叠边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36360114/

相关文章:

javascript - 限制 On Bootstrap 切换开关的总数

html - 如何在图标之间创建垂直虚线(带有示例图像)

html - 如何在电子邮件或电子邮件模板中使用自定义字体

javascript - 如何在顺风CSS中的条件上添加样式

html - Bootstrap 中的一行与多行

javascript - 如何使用 jquery-ui-1.9.2.custom 仅在按钮的左侧添加 border-corner-radius?

javascript - 将一个 div 分成两部分,一半显示在固定 div 下方,一半显示在上方

javascript - 第二个下拉菜单自动更改其值

css - 列、变换和像素舍入问题

css - 如何让图像和文本内联显示?