html - 为什么当我尝试在 html 表格的 tbody 上设置高度和垂直滚动时出现此问题?

标签 html css layout xhtml

我发现通过滚动向该内表的 tbody 添加高度有一些困难:

enter image description here

正如您在我的页面中看到的那样,我有一个 Jquery Accordion 菜单(我认为这不是问题),其中包含一个内部表格(以红色方 block 突出显示)。

这是我的表的代码:

<div>
    <table border="1" class="standard-table-cls" style="width: 70%; float: right;">

        <thead>
            <tr>
                <th width="14.2%">Codice RM</th>
                <th width="14.2%">Autore Firma</th>
                <th width="14.2%">Data Firma</th>
                <th width="14.2%">Acq Riserva</th>
                <th width="14.2%">Consegna Finale</th>
                <th width="14.2%">Descrizione RM</th>
                <th width="14.2%">Imponibile</th>
             </tr>
         </thead>

         <tbody>
             <%
                 int count = 0;
                 for (RM currentRM : salDettaglio.getRM()) {
                     String test = currentRM.getAcqRiserva();
                     String evenOrOdd;
                     if((count & 1) == 0) {
                         evenOrOdd = "even";
                     }
                     else {
                         evenOrOdd = "odd";
                     }
                     count++;
                  %>

                  <tr id="rmRow" class=<%=evenOrOdd %> >
                      <td><%=currentRM.getCodiceRm()%></td>
                      <td><%=currentRM.getAutoreFirma()%></td>
                      <td><%=currentRM.getDataFirma()%></td>
                      <td><%=currentRM.getAcqRiserva()%></td>
                      <td><%=currentRM.getConsegnaFinale()%></td>
                      <td><%=currentRM.getDescrizioneRM()%></td>
                      <td><%=currentRM.getImponibile().toString()%></td>
                  </tr>

               <%}%>
           </tbody>
       </table>
   </div>

这是与此表相关的 CSS:

table.standard-table-cls {
    border: 1px solid #76818a;
    border-collapse: collapse;
    color: #76818a;
    font: 11px Verdana,Geneva,Arial,Helvetica,sans-serif;
    margin: 0 !important;
    table-layout: fixed;
    text-align: center;
    text-decoration: none;
}

table.standard-table-cls th {
    border-bottom: 1px solid #76818a;
    border-left: 1px solid #76818a;
    color: #76818a;
    font-weight: bold;
    overflow: hidden;
    padding: 2px 14px 2px 4px !important;
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}

table.standard-table-cls tr.even {
    background-color: #fffece;
}

table.standard-table-cls tr.odd {
    background-color: #ffffff;
}

好的,现在的问题是我想向 tbody 添加一个 height 并滚动到它(如果内容超出高度。

所以我添加了以下 CSS(我将 tbody 设置为 block 这样我就可以固定它的高度并将溢出设置为滚动 y):

.standard-table-cls > tbody {
    display: block;
    height: 45px;
    overflow-y: scroll;
}

我得到了这个悲惨的结果:

enter image description here

为什么?我错过了什么?我该如何解决这个问题?

谢谢

最佳答案

您是否尝试过最大高度和最小宽度?

关于html - 为什么当我尝试在 html 表格的 tbody 上设置高度和垂直滚动时出现此问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27446421/

相关文章:

javascript - 美元符号未定义

layout - magento中不同类别的不同模板

css - 摆脱水平框阴影,即使它是 0

html - 在换行符中处理边距时,是否有比 `calc` 更简单的替代方法?

css - 纯 CSS 解决方案——方形元素?

CSS 布局(2 列布局,但如果没有侧边栏,主列必须 100% 宽)

html - 位置: absolute in this CSS dropdown menu的作用

html - Accordion 动画中箭头图标的效果

html - Bootstrap 4 添加到 map - 添加额外的主题颜色

jquery - 在父 div 的相对两侧 float 两个类