有谁知道为什么宽度为100%的输入元素会遍历表格的单元格边界。宽度为100%的HTML输入文本框溢出表格单元格
在下面输入框的简单示例中,查看表格的单元格边框,结果非常糟糕。这已经过测试,它的发生方式与Firefox,IE7和Safari相同。
这对你有意义吗? 我错过了什么,你知道一个可能的解决方案吗?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <!-- don't use closing slash in meta tag, it breaks HTML4.01 transitional -->
<title>Test input text in table</title>
<style type="text/css">
table {border-top: 1px solid #ff0000; border-left: 1px solid #ff0000;}
table td {border-right: 1px solid #00ff00; border-bottom: 1px solid #00ff00;}
input[type="text"] {width: 100%;} /* removing this would make input not to go over cells border, but they would be too short, I want them to fit cells size */
</style>
</head><body>
<table cellpadding="0" cellspacing="0">
<tr>
<td><p>column one hello babe babe babe</p></td>
<td><p>column two hello babe more</p></td>
<td><p>column three hello babe more and more</p></td>
</tr>
<tr>
<td><input type="text" value="test"></td>
<td><input type="text" value="test"></td>
<td><input type="text" value="test"></td>
</tr>
</table>
</body></html>
我解决了这个问题如果你只是使用表格来表示输入,你可能会在'ul'或'ol'内切换到使用'form','label'和'input'。这至少稍微有点语义。当然,即使你坚持使用'table',你也应该使用'form'。 – 2010-03-03 16:38:46