gpt4 book ai didi

html - 在 CSS 中居中表格不起作用

转载 作者:行者123 更新时间:2023-11-28 04:57:13 24 4
gpt4 key购买 nike

我正在使用 BlueGriffon并阅读以下链接:

Center-align a HTML table

Center a table

CSS: Centered tables

关于如何使用 CSS 居中表格,因为 align 已被弃用。但是,它们都不起作用,3 个链接中建议的使表格居中的代码如下所示:

.centered-table {
margin-left: auto;
margin-right: auto%;
}

我的代码:

CSS:

.maintbl {
margin-left: auto;
margin-right: auto%;
}

HTML:

 <table class="maintbl" id="tblMain">
<tbody>
<tr>
<td>Hello world<br>
</td>
</tr>
</tbody>
</table>

它没有居中,而是出现在右侧。我把上一个链接的代码直接复制到编辑器里,结果是一样的。什么错误,我该如何解决?

最佳答案

我认为它是表格中心的更好做法。只需在表格标签上使用 css

例子。

 table {
width: 60%;
margin: 0 auto;
}

关于html - 在 CSS 中居中表格不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40319892/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com