【发布时间】:2011-06-30 05:28:01
【问题描述】:
单元格只包含一个复选框。由于表格标题行中的文本,它相当宽。如何使复选框居中(在我的 HTML 中使用内联 CSS?(我知道))
我试过了
<td>
<input type="checkbox" name="myTextEditBox" value="checked"
style="margin-left:auto; margin-right:auto;">
</td>
但这没有用。我究竟做错了什么?
更新:这是一个测试页面。有人可以纠正它 - 在 HTML 中使用 CSS 内联 - 以便复选框在它们的列中居中?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Alignment test</title>
</head>
<body>
<table style="empty-cells:hide; margin-left:auto; margin-right:auto;" border="1" cellpadding="1" cellspacing="1">
<tr>
<th>Search?</th><th>Field</th><th colspan="2">Search criteria</th><th>Include in report?<br></th>
</tr>
<tr>
<td>
<input type="checkbox" name="query_myTextEditBox" style="text-align:center; vertical-align: middle;">
</td>
<td>
myTextEditBox
</td>
<td>
<select size ="1" name="myTextEditBox_compare_operator">
<option value="=">equals</option>
<option value="<>">does not equal</option>
</select>
</td>
<td>
<input type="text" name="myTextEditBox_compare_value">
</td>
<td>
<input type="checkbox" name="report_myTextEditBox" value="checked" style="text-align:center; vertical-align: middle;">
</td>
</tr>
</table>
</body>
</html>
我已经接受了@Hristo 的回答——这里是内联格式......
<table style="empty-cells:hide;" border="1" cellpadding="1" cellspacing="1">
<tr>
<th>Search?</th><th>Field</th><th colspan="2">Search criteria</th><th>Include in report?<br></th>
</tr>
<tr>
<td style="text-align: center; vertical-align: middle;">
<input type="checkbox" name="query_myTextEditBox">
</td>
<td>
myTextEditBox
</td>
<td>
<select size ="1" name="myTextEditBox_compare_operator">
<option value="=">equals</option>
<option value="<>">does not equal</option>
</select>
</td>
<td>
<input type="text" name="myTextEditBox_compare_value">
</td>
<td style="text-align: center; vertical-align: middle;">
<input type="checkbox" name="report_myTextEditBox" value="checked">
</td>
</tr>
</table>
【问题讨论】:
-
将使其在 IE8,9 中工作。但是在 IE10 或 chrome 中,无论您是否看到该框,都会在框内定义复选框或单选框。该框将始终左对齐。但在定义框内,复选框或单选框居中。如果包含 TD 的宽度为 100px,复选框为 50px,则始终左对齐。要使复选框居中,可以将复选框的定义框设为 100px,与包含 TD 的宽度相同。