如何为<td>设置固定宽度? [英] How to set up fixed width for <td>?

查看:20
本文介绍了如何为<td>设置固定宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单方案:

  <tr class="something">
    <td>A</td>
    <td>B</td>
    <td>C</td>
    <td>D</td>
  </tr>

我需要为 设置一个固定的宽度.我试过了:

I need to set up a fixed width for <td>. I've tried:

tr.something {
  td {
    width: 90px;
  }
}

还有

td.something {
  width: 90px;
}

为了

<td class="something">B</td>

甚至

<td style="width: 90px;">B</td>

但是的宽度还是一样的.

But the width of <td> is still the same.

推荐答案

对于 Bootstrap 4.0:

在 Bootstrap 4.0.0 中,您不能可靠地使用 col-* 类(在 Firefox 中有效,但在 Chrome 中无效).您需要使用 OhadR 的答案:

For Bootstrap 4.0:

In Bootstrap 4.0.0 you cannot use the col-* classes reliably (works in Firefox, but not in Chrome). You need to use OhadR's answer:

<tr>
  <th style="width: 16.66%">Col 1</th>
  <th style="width: 25%">Col 2</th>
  <th style="width: 50%">Col 4</th>
  <th style="width:  8.33%">Col 5</th>
</tr>

对于 Bootstrap 3.0:

在 twitter bootstrap 3 中使用:class="col-md-*" 其中 * 是宽度的列数.

For Bootstrap 3.0:

With twitter bootstrap 3 use: class="col-md-*" where * is a number of columns of width.

<tr class="something">
    <td class="col-md-2">A</td>
    <td class="col-md-3">B</td>
    <td class="col-md-6">C</td>
    <td class="col-md-1">D</td>
</tr>

对于 Bootstrap 2.0:

在 twitter bootstrap 2 中使用:class="span*" 其中 * 是宽度的列数.

For Bootstrap 2.0:

With twitter bootstrap 2 use: class="span*" where * is a number of columns of width.

<tr class="something">
    <td class="span2">A</td>
    <td class="span3">B</td>
    <td class="span6">C</td>
    <td class="span1">D</td>
</tr>

** 如果您有 <th> 元素在那里设置宽度,而不是在 <td> 元素上设置.

** If you have <th> elements set the width there and not on the <td> elements.

这篇关于如何为&lt;td&gt;设置固定宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆