css - max-width 对表格没有任何作用
问题描述
我正在尝试一件非常简单的事情(我想),但它不起作用。如果我设置这样的表格样式:
table {
width: 537px;
height: 19px;
max-width: 100%;
}
<table>
<tr>
<td style="background-color: #ffe129;">text</td>
<td style="background-color: #bdff4d;">text</td>
</tr>
</table>
然后表格宽度将537px
即使我的窗口宽度为 400 像素。一个 div 将是400px
.
添加display:block
到表格样式会破坏表格:请参见此处
解决方案
我将定义max-width: 537px;
例如,然后width: 100%
通过这种方式给出如果你说的max-width
是537pxwidth:100%
; 它将始终尊重屏幕的宽度,并且不会超过537px
table
{
width: 100%;
height: 19px;
max-width: 537px;
}
<table>
<tr>
<td style="background-color: #ffe129;"></td>
<td style="background-color: #bdff4d;"></td>
</tr>
</table>
推荐阅读
- python - 为什么我调用 draw_petal(brad) 时没有形成循环?
- d3.js - D3 - 从 enter() 调用函数
- multithreading - 在主函数以外的函数中使用 std::async 时的作用域块
- c++ - Boost Spirit 定点作为整数解析器
- laravel-5.4 - ItemList 的替代品,可在单页中多次使用
- azure - 为我的 Azure 功能选择哪个计划:消费计划或应用服务计划?
- python - Selenium 获取下一个 tr 给定条件为前一个 tr 成立
- python - 将字符串格式化为 csv
- spss - 比较不同行中的值以创建新变量
- eclipse - Eclipse 平台中的循环依赖