如何使表格td tr根据文本长度自动宽度
How to make table td tr auto width based on text length?
我有一个宽度为100%的表,如何根据文本长度自动宽度设置TD和TR?我使用了宽度:auto,但它不起作用。这是我的代码:
.hoverTable {
width: 100%;
border-collapse: collapse;
}
.hoverTable td {
padding: 7px;
border: #4e95f4 1px solid;
}
/* Define the default color for all the table rows */
.hoverTable tr {
background: #b8d1f3;
}
/* Define the hover highlight color for the table row */
.hoverTable tr:hover {
background-color: #ffff99;
}
.hoverTable th {
background: #b8d1f3;
}
<table class="hoverTable">
<tr>
<th colspan="3">Some Text here</th>
</tr>
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td>This is text length example and text</td>
<td>Item 1B</td>
<td>Item 1C</td>
</tr>
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td>Item 2A</td>
<td>Item 2B</td>
<td>Item 2C</td>
</tr>
<th colspan="3" class="width: 100%;">Some Text here</th>
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td>Item 3A</td>
<td>Item 3B</td>
<td>Item 3C</td>
</tr>
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td>Item 4A</td>
<td>Item 4B</td>
<td>Item 4C</td>
</tr>
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td>Item 5A</td>
<td>Item 5B</td>
<td>Item 5C</td>
</tr>
</table>
正如您在中看到的,这是文本长度示例,文本宽度不是基于文本长度的,我如何根据文本长度设置宽度。。
我的意思是基于文本长度的自动宽度?
感谢
使用以下内容:
.hoverTable {
border-collapse: collapse;
}
所以只要移除width: 100%;
,它就会工作。现在将动态呈现该表。
Fiddle:单击
相关文章:
- 将HTML表格导出到带有文本和图像的excel中
- 如何将表格中的文本添加到使用按钮输入的文本区域
- 单击每个表格行中的复选框时启用文本框
- Mvc表格如何更改文本的颜色条件
- 设置“;将标签视为文本“;通过脚本将Google电子表格图表的值设置为true
- “搜索”文本仅考虑表格中的最后一列
- 在表格或所需位置下方弹出文本
- 与表格中的文本完美对齐
- 在输入字段之前提取表格单元格中的文本
- 循环通过表格查找第一个具有 CSS CSSstablelisttdselect 的 TD 文本
- 使用外部 javascript 更改多个表格单元格中的文本
- 是否可以使用 javascript 读取文本或电子表格文件
- JQuery 显示来自可见 HTML 表格单元格的文本的串联列表
- 如何使用JavaScript在HTML表格中获取td内部的链接文本
- jQuery将文本添加到放置在表格单元格中的图像中
- 如何防止 td 中的文本破坏表格的对齐方式
- 根据单元格内容更改表格行的文本颜色,仅使用 css
- 使用 javascript 将表格单元格中的文本制作到 URL
- 从 html 表格单元格中获取内容值,并使用 javascript 使其显示在文本框中
- 使用谷歌融合表格地图的网页文本/JavaScript未显示