在设计一个主页时,我遇到了以下问题:我想显示一个表-表列的数量可以用复选框选择。此外,我的网站应该在手机上工作,所以我放入相应的元行。
不幸的是,我的网站不能正常工作,因为它不显示我的水平滚动条。
PHP代码:echo '<table id="dynamictable">';
echo '<tr>';
foreach($res_category_arr as $columnname)
{
echo '<th>' . $columnname. '</th>';
}
echo '</tr>';
if (mysqli_num_rows($result) > 0)
{
while($data_current_row=mysqli_fetch_assoc($result))
{
echo '<tr>';
foreach($res_category_arr as $tabledata)
{
echo '<td>' . $data_current_row[$tabledata] . '</td>';
}
echo '</tr>';
}
}
echo '</table>';
res_category_arr表示一个数组,其中包含所需的列名。CSS代码:
#dynamictable{
width: 100%;
overflow-y: auto;
margin: 0 0 1em;
text-align: center;
}
#dynamictable::-webkit-scrollbar {
-webkit-appearance: none;
width: 14px;
height: 14px;
}
#dynamictable::-webkit-scrollbar-thumb {
border-radius: 8px;
border: 3px solid #fff;
background-color: rgba(0, 0, 0, .3);
}
将ID从表中删除,并将其放在周围的div 上。
它应该做你想要的,但你可能还想添加一个width:100%回到表。
编辑:我想我会在这里添加一个简单的工作示例。http://codepen.io/anon/pen/qaGARr?editors=1100 0
.scroll {
overflow-x:auto;
width:100%;
}
table {
width:100%;
min-width:700px;
}
如果宽度小于700px,滚动条就会出现