html - 如何向我的表格添加滚动条?

标签 html css

我希望我的 table 有一个滚动条,这样页面的高度就不会太高,我尝试了很多我搜索过的答案,但没有任何反应。这是我的代码。

  <div class="text">List Of Product </div>
  <div id="tableContainer" class="tableContainer">
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="scrollTable">
<thead class="fixedHeader">
<tr>
 <th>Image</th>
 <th>Item Name</th>
 <th>Item Price</th>
 <th>Item Description</th>
 <th></th>
 </tr>
 </thead>
<?php
    include('config.php');
    $result2 = mysql_query("SELECT * FROM category");
    while ($row2 = mysql_fetch_array($result2)) {
        $ble = $row2['id'];
        $result3 = mysql_query("SELECT * FROM athan_products where product_id='$ble'");
        echo '<tbody class="scrollContent">';
        echo "<tr>";
        while ($row3 = mysql_fetch_array($result3)) {
            echo '<td class="templatemo_pizza_box"><img alt="Motor" src="images/motor/'       . $row3['product_photo'] . '" width="65px" height="65px" /></a></td>';
            echo '<td class="textbox"> ' . $row3['partsname'] . ' </td>';
            echo '<td class="textbox"> ' . $row3['price'] . ' </td>';
            echo '<td class="textbox"> ' . $row3['description'] . '     </td>';
                                                                      echo '<td><a rel="facebox" href=portal.php?id=' .      $row3["product_id"] . '><input type="submit" value="Add to Cart"/></td>';
        }
        echo '</tr>';
        echo "</tbody>";
    }
?>
</table>
</div>

最佳答案

对于要滚动的元素,您需要给出高度,以及当它溢出该高度时会发生什么。 例如:

<table style="height:20px;overflow-y:scroll">....</table>

当内容高度超过 20px 时,将导致表格出现滚动条

关于html - 如何向我的表格添加滚动条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20415065/

相关文章:

html - 悬停时居中文本

javascript - 在 Javascript 中如何使鼠标悬停在链接上时可见?

css - 如何在 CSS 中制作这样的进度条

php - WordPress 菜单帖子特色图片

javascript - 定位分离的 DOM 树内存泄漏

javascript - 单击一次页面链接时,导航/汉堡包图标消失

javascript - 如何从文本文件中获取文本并将其显示在 <table> 中?

css - 带边框半径的 HTML5 和 CSS 标题视频

jquery - 动态 DOM 元素上的 webKit 转换

css - 字体在 mozilla 和 chrome 中不起作用