如何在HTML或CSS中指定表单元格的绝对最小宽度 [英] How do I specify in HTML or CSS the absolute minimum width of a table cell

查看:183
本文介绍了如何在HTML或CSS中指定表单元格的绝对最小宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确保表格单元格不能小于某个最小宽度的最佳方法是什么。

What's the best way to ensure a table cell cannot be less than a certain minimum width.

我想确保表格中的所有单元格的宽度至少为100像素的表容器。如果有更多可用空间,表格单元格应填充该空格。

I want to ensure that all cells in a table are at least 100px wide regards of the width of the tables container. If there is more available space the table cells should fill that space.

喜欢找到一个在


  • IE 6-8

  • / li>
  • Safari

按偏好顺序。

推荐答案

这个CSS应该足够了:

This CSS should suffice:

td { min-width: 100px; }

但是,并不是所有浏览器都能正确地遵守min-width属性,IE6不喜欢它)。

However, it's not always obeyed correctly (the min-width attribute) by all browsers (for example, IE6 dislikes it a great deal).

编辑:对于IE6(和之前的)解决方案,可靠地在所有情况下,据我所知。使用nowrap HTML属性并不能真正实现所需的结果,因为它只是防止单元格中的换行符,而不是指定最小宽度。

As for an IE6 (and before) solution, there isn't one that works reliably under all circumstances, as far as I know. Using the nowrap HTML attribute doesn't really achieve the desired result, as that just prevents line-breaks in the cell, rather than specifying a minimum width.

但是,如果nowrap与常规单元格宽度属性(例如使用width:100px)结合使用,100px将像一样起作用,最小宽度,单元格仍然会随文本扩展(由于nowrap) 。这是一个不太理想的解决方案,它不能使用CSS完全应用,因此,如果你有很多表,你希望应用它,将是繁琐的实现。 (当然,如果你想在你的单元格中有动态换行符,这整个替代解决方案会失败)。

However, if nowrap is used in conjunction with a regular cell width property (such as using width: 100px), the 100px will act like a minimum width and the cell will still expand with the text (due to the nowrap). This is a less-than-ideal solution, which cannot be fully applied using CSS and, as such, would be tedious to implement if you have many tables you wish to apply this to. (Of course, this entire alternative solution falls down if you want to have dynamic line-breaks in your cells, anyway).

这篇关于如何在HTML或CSS中指定表单元格的绝对最小宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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