【发布时间】:2018-05-16 01:36:38
【问题描述】:
我仍然是 Web 开发的学生,我想将每个表头对齐到每个列的中心,但我似乎无法做到。我尝试将 align="center" 添加到我的每个 <th> 元素中,但它仍然失败。难道是因为我的模态?它一直居中,直到我将模态添加到表格数据中。
<body>
<h1 align="center">OVERTIME REQUEST</h1>
<table align="center" style="width:100%">
<th align="center">Date</th>
<th align="center">Remarks</th>
<th align="center">Start</th>
<th align="center">End</th>
<th align="center">Total</th>
<th align="center">Employee's Signature</th>
<th align="center">Leadman</th>
<th align="center">Time-Keeper</th>
<tr>
<form>
<td align="center"><input type="text"></td>
<td align="center"><input type="text"></td>
<td align="center"><input type="text"></td>
<td align="center"><input type="text"></td>
<td align="center"><input type="text"></td>
<td align="center"><span class="container" align="center">
<!-- Trigger the modal with a button -->
<button type="button" style="margin:auto;" class="btn btn-info btn-sm" data-toggle="modal" data-target="#myModal">Upload Signature</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content" >
<div class="modal-header" align="center">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<iframe src="test.html" height="450" width="600" align="center"></iframe>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</span>
</td>
</form>
</table>
</body>
另外,我想去掉每个表格数据中的填充,所以我把它加到了我的脑海中:
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 0px;
}
</style>
但它也不起作用。有什么我看不到的问题吗?
this is what my page looks like
this is what it should look like or atleast almost
*编辑:
我已经在我的页面中添加了以下 css 内部样式,但它仍然无法使我的表头居中:
th{
text-align: center;
}
然而,如果我把它作为一个内联样式,它工作得很好。怎么可能?似乎是什么问题?
【问题讨论】:
-
align是 HTML5 规范的过时属性。只需使用 text-align css 样式.. 根据文档:“要实现与左、中、右或对齐值相同的效果,请将 CSS text-align 属性应用于元素。” - developer.mozilla.org/en-US/docs/Web/HTML/Element/th