在td元素中

时间:2017-12-04 15:18:25

标签: html css html-table

我有一张失败的大桌子要做。 我总是觉得难以将它们风格化,所以我可以认为我的是一个基本问题。 我有一些TD有很长的文字。目前,表格样式设置为" white-space:nowrap"。

我想要实现的是将这些td文本拆分为固定数量的"行" (让我们说3)所以行可能更高,单个单元格更小。

空格正常:

--------
- text -
- text -
- text -
- text -
- text -
--------

white-space:nowrap

---------------------------------
- text text text text text text -
---------------------------------

我想:

-------------
- text text -
- text text -
- text      -
-------------

1 个答案:

答案 0 :(得分:1)

在列上指定宽度以确定要在其中放置多少文本。我创建了一个JS小提琴,其中包含3个如何工作的例子:

https://jsfiddle.net/2rhzymwc/

<table class="wrap-width">
<tr>
<td>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</td>
<td>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</td>
<td>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</td>
</tr>
</table>

.wrap-width td {
  width: 100px;
}

修改

关于你的评论,你的意思是指长度比内容略长吗?或者一个细胞的宽度/高度应该比其他细胞长?目前还不清楚你要求的是什么,请看看这些进一步的例子:

https://jsfiddle.net/jz8gn8ax/