限制 HTML 表格的宽度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12802290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Limit width of HTML table
提问by iomartin
I'm trying to write a table so that it doesn't expand to the full width of the page. Below is what I have so far, but even though the first columns seem to respect the "width" parameter, the last column expands to the end of the page.
我正在尝试编写一个表格,以便它不会扩展到页面的整个宽度。下面是我到目前为止所拥有的,但即使第一列似乎尊重“宽度”参数,最后一列也会扩展到页面的末尾。
All results I found use CSS, but I am not sure how to do that. I don't know if it's relevant, but I'm writing a Joomla! article.
我发现的所有结果都使用 CSS,但我不知道该怎么做。我不知道它是否相关,但我正在写一个 Joomla!文章。
<table class="zebra" width="300">
<thead>
<tr>
<th style="text-align: left;" width="100">title 1</th>
<th style="text-align: center;" width="100">title 2</th>
<th style="text-align: center;" width="100">title 3</th></tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;" width="100">content 1</td>
<td style="text-align: center;" width="100">content 2</td>
<td style="text-align: center;" width="100">content 3</td>
</tr>
</tbody>
</table>
回答by PhonicUK
<table class="zebra" style="max-width:300px;">