Html 表 align="center" 似乎不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7106298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 10:08:17  来源:igfitidea点击:

Table align="center" doesn't seem to be working

htmlcss

提问by Burt

回答by Marius Solbakken Mellum

You need to set this on the <td> elements.

您需要在 <td> 元素上设置它。

You should also use text-align: center in css, not align="center" in html.

您还应该在 css 中使用 text-align: center,而不是在 html 中使用 align="center"。

回答by Sascha Galley

If you want to have the table centered use:

如果您想让表格居中,请使用:

.content-table {
    margin: 0 auto;
}

if you want to have the td text centered use:

如果您想让 td 文本居中,请使用:

.content-table td {
    text-align: center;
}

回答by max4ever

while there are many ways to do with css, divs, and style property and stuff the simpliest way is not to use align="center" but to wrap the table in <center> </center>tag :)

虽然有很多方法可以处理 css、div 和样式属性和东西,但最简单的方法不是使用 align="center" 而是将表格包装在<center> </center>标签中:)

Note: the centerelement is considered obsolete in HTML5.

注意:该center元素在 HTML5 中被认为是过时的

回答by sandesh mahajan

there are two things you need to do

你需要做两件事

  1. need to have width in pixel or %

  2. margin: 0 auto; or i.e margin-left:auto & margin-right:auto

    .search-box table{ height: 100%; width: 50%; margin: auto; }

  1. 需要以像素或%为单位的宽度

  2. 边距:0 自动;或即 margin-left:auto & margin-right:auto

    .search-box 表格{高度:100%;宽度:50%;保证金:自动;}

回答by kollein

You should use CSS selector with Attribute align="center" like below:

您应该使用 CSS 选择器和 Attribute align="center" ,如下所示:

table[align="center"] {
    margin: 0 auto;
}