css - 在我的网站的移动版本上显示表格时出现问题
问题描述
我已经尝试解决这个问题 10 天了,但我仍然找不到任何解决方案。
我有一个在桌面版本上完美显示的表格,但在移动设备上它超出了页面区域,我还尝试@media screen max width 600px 来修改表格的大小并溢出隐藏但仍然无法正常工作,我将粘贴代码以下:
<style type="text/css">
table {
border-collapse: collapse;
width: 100%;
}
td {
border: 1px solid #d3d3d3;
text-align: center;
white-space: nowrap;
}
th {
background-color: #0288D1;
border: 2px solid #d3d3d3;
text-align: center;
font-size: large;
color: white;
text-transform: uppercase;
}
</style>
<table>
<thead>
<tr>
<th colspan="4" style="background-color:#0277BD"><strong>Some Text Here<strong></th></tr>
<tr>
<th><strong>Some Text Here</strong></th>
<th><strong>Some Text Here</strong></th>
<th><strong>Some Text Here</strong></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<a rel="nofollow" target="_blank" href="https://somesite.com/play"><img width="200" height="80" src="https://somesite.com/image.png" alt="Some Text Here"></a>
</td>
<td><strong><font color="green">Some Text Here</font></strong></td>
<td>Some Text Here</td>
<td>
<div>
<button class="playblock" style="display:block;width:150px;height:50px;background-color:#4CAF50;margin-bottom:5px;color:white;font-size:20px;cursor:pointer;text-align:center;" onmouseover="this.style.backgroundColor='green'" onMouseOut="this.style.backgroundColor='#4CAF50'" onclick="window.location.href = 'https://somesitehere.com/play';">PLAY</button>
</div>
<div>
<button class="reviewblock" style="display:block;width:150px;height:50px;background-color:#EB9C12;color:white;font-size:20px;cursor:pointer;text-align:center;" onmouseover="this.style.backgroundColor='orange'" onMouseOut="this.style.backgroundColor='#EB9C12'" onclick="window.location.href = 'https://somesitehere.com/see/';">REVIEW</button>
</div>
</td>
</tr>
解决方案
这是移动端表格的常见问题。目前尚不清楚您是否使用表格进行布局,或者您是否将拥有更多的数据行Play
和Review
链接。
- 如果您将其用于布局,我建议您
flexbox
改为探索布局。 - 如果您计划在表格中包含更多行,您可以将表格包装在一个
<div>
withmax-width: 100%; overflow: auto;
中,这将允许 div/table 水平滚动但不会影响页面的布局。在较小的屏幕上将其与减小的字体大小配对,IMO,您会在移动设备上获得一个非常实用的表格。 - 有一些方法可以通过使用
data-title
数据属性<td>
(如所有的表格元素和样式它们有点像每一行都是它自己的表格。 这是 CSS Tricks 的一个示例:https ://css-tricks.com/responsive-data-tables/<th>
::before
td::before { content: attr(data-title); }
display: block;
推荐阅读
- python - 如何在函数中返回多个图
- sql - 使用 NULL 参数调用雪花函数
- github-pages - Vuepress 站点在 github 页面上部署时无法正确加载
- php - 为什么当我在 mysql 中使用 whereRaw 和 where 时会得到不同的结果
- json - 如何为我的库存和 set_fact 中的每个主机选择一个嵌套的 json 值以供以后重用
- networking - 屏幕共享、TCP 或 Reliable UDP 哪种方式更快?
- solidity - 如何在 ropsten etherscan 上查看已部署的 Solidity 合约代码
- vim - 在行中保存准确的光标位置
- python - 在 Python 中从 JSON 中提取数据:错误 - “列表索引必须是整数或切片,而不是 str”
- css - 在父 div 中定位 div