html - 内表内容与外表不对齐

标签 html css html-table border cellpadding

我正在另一个表中创建一个表。我已将列划分为与外表完全相同的比例。但是,这些列未与外部表列对齐。谁能告诉我我错过了什么?

<html>
	<div style="overflow:scroll;height:140px;width:100%;overflow:auto"  style="background-color:black">
		<table width="100%" style="padding:0; margin:0;"  cellpadding="0">
			<tr class="tbl_header"  cellpadding="0">
				<td width="3%">test1</td>
				<td width="7%">test2</td>
				<td width="3%">test3</td>                               
				<td width="12%">test4</td>
				<td width="7%">test5</td>
				<td width="10%"test6</td>                               
				<td width="7%">test7</td>  
			</tr>
			<tr  style="background-color:yellow">
				<td colspan="7" style="background-color:yellow">
					<div style="overflow:scroll;height:110px;width:100%;overflow:auto;border:none;background-color:green">
						<table width="100%" style="border:none;background-color:red" cellpadding="0">
							<tr class="even">
								<td width="3%">2</td>
								<td width="7%" class="tdAlign">Testing </td>
								<td width="3%" class="tdAlign">Testing </td>
								<td width="12%" class="tdAlign">Testing Testing Testing</td>                     
								<td width="7%">Testing_1</td>
								<td width="10%">Testing_2</td>  			
								<td width="7%">Testing_3</td>
							</tr>
						</table>
					</div>
				</td>
			</tr>
		</table>
	</div>
</html>

最佳答案

当我使用 chrome web 工具包检查表格时。由于文本长度的原因,我看到表格应该是 3%。你可以通过添加 table-layout: fixed 来解决这个问题给你的<table>元素。

如果您想使用表格标题,我建议使用 <th> ( see here )

关于html - 内表内容与外表不对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48315827/

相关文章:

html - 将子div扩展到父级的高度?

html - 有没有办法让 Chris Coyier 的响应式 "list"表具有动态内容?

javascript - 第一次单击按钮后图像 slider 卡住

javascript - 如何使 float 标题列水平滚动并防止它们左对齐?

javascript - JS 读取 XML 文件,为多个 div 编写 HTML 代码,然后重复自身直到到达列表末尾

html - 如果事件下 zipper 接,文本下划线

javascript - 按住某个键时在悬停时更改样式

html - 如何在无序列表上设置点并将它们更改为悬停时的图像

javascript - 如何将<table>拆分成多个<div>?

wordpress - title 属性是否适用于 HTML 表格或是否有特定的解决方案?