【发布时间】:2019-07-25 10:00:52
【问题描述】:
一个我无法找到答案的不寻常问题:
是否可以使用 width 属性覆盖带有 css 样式的表格。
我希望 html 表默认为 width 或 100%(使用 css),除非在标记中将数字 width 参数传递给我的表。
现在,如果我在 css 中将表格的 width 设置为 auto,我可以使用 width 属性覆盖宽度,方法是将其应用于标记中的 table 元素。但是,auto 的宽度不默认为 100%。如果我在 css 中将表格的 width 设置为 100%,则无法使用 width 属性覆盖宽度,方法是将其应用于标记中的 table 元素。
有没有人知道一种变通方法,这样我就可以把我的蛋糕也吃了?
.table-a {
width: 100%;
border: 1px solid black;
margin: 48px auto 16px;
}
.table-b {
width: auto%;
border: 1px solid black;
margin: 48px auto 16px;
}
<table class="table-a" width="200">
<tr>
<td>Foo</td>
<td>Bar</td>
</tr>
</table>
<table class="table-b" width="200">
<tr>
<td>Foo</td>
<td>Bar</td>
</tr>
</table>
<table class="table-b">
<tr>
<td>Foo</td>
<td>Bar</td>
</tr>
</table>
<p>Table A seems to show that the width attribute will not override external stylesheets the same way inline stylesheets.</p>
<p>Is there a way to ensure that when a width attribute is not passed to a table, that it defaults to 100%, and otherwise adheres to the width declaration/</p>
【问题讨论】:
-
你可以发布你的代码 sn-p 吗?
标签: html css html-table width