【发布时间】:2016-02-13 13:24:21
【问题描述】:
如何防止内容与单元格边框重叠,使内容留在单元格中。我不希望设置fixed 宽度,因为内容的长度可能会有所不同。
查看示例:http://jsfiddle.net/1mmh7510/5/
CSS
.rotate {
height: 400px;
}
.rotate > div {
-webkit-writing-mode:vertical-rl;
-ms-writing-mode:tb-rl;
writing-mode:vertical-rl;
transform: rotate(-180deg);
}
HTML
<table style="background-color:#e4e6ea;" border="0" cellspacing="1">
<tbody>
<tr class="tableheader-row-dashboard">
<td style="background-color:white;"width="90px"> Date</td>
<td style="background-color:white" width="90px">Phone No</td>
<td style="background-color:white; vertical-align: bottom;" class="rotate" width="20px"><div>Test.. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. Test.. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.</div></td>
</tr>
<tr class="tablerow-rowd">
<td class="text">06/11/2015</td>
<td class="text">1234567890</td>
<td class="text">X</td>
</tr>
</tbody>
</table>
编辑:
看起来 CSS 是不可能的。使用jQuery如何获取内容的宽度,然后将其设置为td的固定宽度?
【问题讨论】:
-
您是否有理由旋转 -180 并应用书写模式,而不是旋转 -90?通过使用
transform-origin: top left; transform: rotate(-90deg);,至少文本保留在框内。据我所知,如果不使用 JS,就不可能使盒子完美贴合。 -
@gummbahla 啊,我明白了。在这种情况下我需要在 JS 中做什么?
-
@I'll-Be-Back 这能解决你的问题吗jsfiddle.net/1mmh7510/8 请告诉我谢谢
-
@GibboK 不,您包含了固定宽度。这无济于事,因为每个字段都有不同的内容长度,例如 jsfiddle.net/1mmh7510/9 - 具有自动宽度将是最佳选择。
标签: javascript jquery css