我有一個三列表格,我想根據內容的長度在單元格中設置文本背景。但是當我設置float:left時,單詞換行不起作用。CSS:在HTML表格中,自動換行不適用於float:left
table {
table-layout: fixed;
width: 100%;
word-wrap: break-word;
}
這是每個單元格中的內容。
.read{
min-height: 20px;
margin-top: 10px;
margin-bottom: 10px;
margin-left: 10px;
padding: 0px 10px 0px 10px;
border-radius: 4px;
background-image: -webkit-gradient(linear, 25% 0%, 25% 100%, from(rgba(142, 175, 196, 1.0)), to(rgba(118, 146, 164, 1.0)));
float:left;
}
<table>
<tr>
<td width="36px">..</td>
<td>
<div class="read">
looooooooooooooooooooooooooooooooooooooooooooooooooooooooooog
</div>
</td>
</tr>
</table>
如果我刪除float:left ;,背景將不匹配內容的長度,但文字換行確實有效。 我該如何修改我的CSS?
你可以嘗試添加顯示:inline-block;到你的.read類? – ppp 2012-07-27 09:44:59
分享您的標記請 – 2012-07-27 09:45:27
http://stackoverflow.com/questions/5889508/using-word-wrap-break-word-within-a-table – Prashobh 2012-07-27 09:48:40