css - 如何为div中的水平溢出添加样式
问题描述
我有下表,我想overflow-x
在 in 中添加样式container
。
我试过了,但对我不起作用(Chrome):
.container::-webkit-scrollbar:horizontal {
width: 10px;
}
.container::-webkit-scrollbar-thumb:horizontal {
height: 20px;
background: hsla(0, 0%, 53.3%, .4);
}
和
.container::-webkit-scrollbar {
width: 10px;
}
.container::-webkit-scrollbar-thumb {
height: 20px;
background: hsla(0, 0%, 53.3%, .4);
}
<div class="container">
<table>
<thead>
<tr>
<th>Column A</th>
<th>Column B</th>
<th>Column C</th>
<th>Column D</th>
<th>Column E</th>
<th>Column F</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1 Cell 1</td>
<td>Row 1 Cell 2</td>
<td>Row 1 Cell 3</td>
<td>Row 1 Cell 4</td>
<td>Row 1 Cell 5</td>
<td>Row 1 Cell 6</td>
</tr>
<tr>
<td>Row 2 Cell 1</td>
<td>Row 2 Cell 2</td>
<td>Row 2 Cell 3</td>
<td>Row 2 Cell 4</td>
<td>Row 2 Cell 5</td>
<td>Row 2 Cell 6</td>
</tr>
<tr>
<td>Row 3 Cell 1</td>
<td>Row 3 Cell 2</td>
<td>Row 3 Cell 3</td>
<td>Row 3 Cell 4</td>
<td>Row 3 Cell 5</td>
<td>Row 3 Cell 6</td>
</tr>
</tbody>
</table>
</div>
.container {
width: 30em;
overflow-x: auto;
white-space: nowrap;
}
table, th, td {
border: 1px solid black;
}
th, td {
padding: .5em 1em;
}
解决方案
运行它,它对你有用吗?
<div class="container">
<table>
<thead>
<tr>
<th>Column A</th>
<th>Column B</th>
<th>Column C</th>
<th>Column D</th>
<th>Column E</th>
<th>Column F</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1 Cell 1</td>
<td>Row 1 Cell 2</td>
<td>Row 1 Cell 3</td>
<td>Row 1 Cell 4</td>
<td>Row 1 Cell 5</td>
<td>Row 1 Cell 6</td>
</tr>
<tr>
<td>Row 2 Cell 1</td>
<td>Row 2 Cell 2</td>
<td>Row 2 Cell 3</td>
<td>Row 2 Cell 4</td>
<td>Row 2 Cell 5</td>
<td>Row 2 Cell 6</td>
</tr>
<tr>
<td>Row 3 Cell 1</td>
<td>Row 3 Cell 2</td>
<td>Row 3 Cell 3</td>
<td>Row 3 Cell 4</td>
<td>Row 3 Cell 5</td>
<td>Row 3 Cell 6</td>
</tr>
</tbody>
</table>
</div>
<style>
.container {
width: 30em;
overflow-x: auto;
white-space: nowrap;
}
table, th, td {
border: 1px solid black;
}
th, td {
padding: .5em 1em;
}
</style>
推荐阅读
- c++ - 类成员的变量类型
- node.js - WebRtc 与 nodeJS 并做出反应
- python - 在python中确定异常值的列表索引
- excel - 如何在电源查询中对同一行中的数字求和?
- javascript - 如何在 react-intl 中格式化句子中的特定单词
- html - 使用 jquery 在 html 代码中显示下拉列表的选定值
- ms-access - 使用文本提取更新查询
- cmake - 在 Windows / Clion /Cmake 中链接 MKL 库
- scala - 比较 Scala 中 DataFrame 的特定行
- c# - 窗口关闭时刷新 WPF MVVM Datagrid