table表格整體居中 和 table表格中各行各列內容居中


1.table表格整個居中
<div style="text-align: center;">
<table border="1" style="margin: auto;" width='60%'>
......
</table>
</div>
我們在table外圍div中加入樣式style="text-align: center;",會發現table表格居中不生效,原因最后說。
所以我們在 <table border="1" style="margin: auto">加入style="margin: auto"會發現table表格整個居中。
2.table表格各行各列中內容居中
可以在table外圍div中加入樣式style="text-align: center;"讓表格中內容居中。為了看的清楚可以為table表格設置一個寬度。
或是單獨的在<td style="text-align: center;"></td>加入樣式都能實現。
為什么style="text-align: center;"不能使table表格整個居中??
答:我們先要明白。text-align:屬性代表的是元素中文本的水平對齊方式,說的更具體點就是設置塊級元素內文本的水平對齊方式。只針對文本內容。


style="text-align: center;"


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM