防止文本与表格 td 宽度重叠
如何限制表 条目在整个屏幕上扩展 条目太长?
How can I restrict the table <td>
entry to expanding over the entire screen when
the entry is too long?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
嗯,CSS 中有
max-width
、max-height
和overflow
。因此,
将最大宽度和高度限制为 150 像素,并且可以是小于 150 到 150 之间的任何内容,任何不适合的内容都将被剪掉并隐藏在视图中。
Overflow 的默认值(
overflow:visible;
)是简单地允许任何不适合其指定容器的内容溢出到其外部。如果您只想水平限制它并且不想隐藏任何内容,word-wrap
可能会有所帮助:word-wrap
会在需要时中断单词,即使它不是在单词的末尾。如果您根本不希望表格扩展或缩小,您也可以仅使用height
和width
指定固定大小。Well, there's
max-width
,max-height
, andoverflow
in CSS.So
would restrict the maximum width and height to 150px, and it can be anything from less than 150 up to 150, and anything that doesn't fit inside that will be clipped off and hidden from view.
Overflow's default (
overflow: visible;
) is to simply allow anything that won't fit inside its specified container to just spill over outside of it. If you only want to limit it horizontally and don't want to hide anything,word-wrap
may help:word-wrap
will break words whenever it needs to, even if it's not at the end of a word. You can also just useheight
andwidth
to specify a fixed size if you don't want the table to expand or shrink at all.您可以使用
word-wrap:break-word;
,这样过长的单词就会被换行。You could use
word-wrap:break-word;
, so overlong words get wrapped.将 100px 替换为您想要的宽度。 1000px 对于网站来说是一个很好的宽度,因为它几乎适合人们现在拥有的所有显示器,因此,如果您有 20 列,则将其设置为 50px。
replace 100px with however wide you want. 1000px is a good width for websites as it will fit on nearly all monitors people have today, so if you had 20 columns then make it 50px for example.
您需要同时指定
max-width
和display
样式(因为 display 属性设置得很有趣,因为它是 td,而不是普通元素)例如You need to specify BOTH the
max-width
anddisplay
styles (because the display attribute is set funny because it's a td, not a normal element) e.g.还有一个很好的解决方案,属性 max-width: 0px;所以它将负责表格的整个宽度。
There is also nice solution with property max-width: 0px; so it will be responsible to full width of table.