我尝试在中间单元格中实现响应表宽度text-overflow: ellipsis;
,如下所示:| Button 1 | A one-lined text that is too long and has to be... | Button 2 |
整个表应该有width: 100%;
与设备一样大。我不能在Button 1
或Button 2
上设置固定的宽度,因为应用程序是多语言的(max-width
应该是可能的)。
我可以尝试任何我想尝试的东西,...
只在我设置固定宽度时出现。我如何在没有JavaScript的帮助下告诉中间的单元格“使用可用空间”?
7条答案
按热度按时间jm2pwxwz1#
这并不是一个真正干净的解决方案,但它不使用JS,并且在我测试过的每一个浏览器中都能工作。
我的解决方案是将单元格的内容 Package 在一个包含
table-layout: fixed
和width: 100%
的表中。参见demo。
以下是完整的解决方案:
侧边按钮的意图并不清楚,因此我使用
white-space: nowrap
将它们保持在同一行中。根据用例,您可能更喜欢应用min-width
并让它们自然换行。wsewodh22#
在表格上设置100%宽度并指定
fixed
表格布局:然后,为应该具有省略号的任何表格单元格设置以下内容:
瞧!响应表与省略号溢出!
演示:http://jsfiddle.net/VyxES/
0h4hbjxa3#
HTML
CSS
ercv8c1e4#
一个更简洁的方法是简单地在td上设置一个max-width。
根据@Fabrício Matte的回复,
http://jsfiddle.net/V83Ae/89/
然后呢
我不知道为什么这样做,但它确实如此,所以如果有人能弄清楚为什么应用最大宽度工程,那么请让我知道,因为我是偶然做到的。
mspsb9vt5#
在撞了我的头几个小时后,没有解决办法,终于找到了。
你想作为溢出底部的元素需要一个最小/最大宽度,其中最大宽度小于最小宽度。然后你可以溢出元素或它的子元素,在那里你可以用你选择的任何方式设置:%,px,auto.
我在不止一个棘手的情况下尝试过,它对所有人都有效。
我会试着用我的例子贴一个文件,但这应该会帮助你去。
yiytaume6#
Here you go
诀窍是设置一个表格布局,其中一个单元格首先占用剩余空间(css表格,请注意!)。
然后添加你的文字,约束自己。
dffbzjpn7#
[更新]我的道歉,似乎不工作'就像这样':http://jsfiddle.net/kQKfc/1/
不过会把它留在这里,因为在某些情况下它会为我们做些什么。
[/update]
我们的项目中有这样的CSS,给予看: