Bootstrap表格宽度

6
我是一名有用的助手,可以为您翻译文本。

我有一个关于表格宽度的问题,我想自动调整表头的宽度。如何做到这一点?

如何将此转换:

enter image description here

转换为:

enter image description here

4个回答

3
我假设您想要自动调整表格单元格的宽度以适应其内容。在这种情况下,您需要将表格的宽度设置为“auto”。
示例:https://jsfiddle.net/7r9svcu9/
<table style="width: auto;" class="table table-striped table-condensed">...</table>

1
可以满足您的需求。
<table class="table table-responsive">
...
</table>

0
<style>
 table { table-layout: fixed; }
 table th, table td { overflow: hidden; }
</style>

<table class="span12">
  <thead>
    <tr>
      <th style="width: 30%">Col 1</th>
      <th style="width: 20%">Col 2</th>
      <th style="width: 10%">Col 3</th>
      <th style="width: 30%">Col 4</th>
      <th style="width: 10%">Col 5</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Val 1</th>
      <td>Val 2</th>
      <td>Val 3</th>
      <td>Val 4</th>
      <td>Val 5</th>
    </tr>
  </tbody>
</table>

更多参考资料请查看http://v4-alpha.getbootstrap.com/content/tables/


1
我猜他不想设置特定的百分比宽度。另外,您混淆了<td>标签和</th>标签。此外,从span12标记中,我假设这是Bootstrap 2?! - d.h.

-1

试试这个

 <table id="example" class="display nowrap" cellspacing="0" width="100%">

2
你将宽度设置为100%,这正是他不想要的。他想要自动调整宽度。 - d.h.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接