如何使标题在表格单元格中居中
如何居中
我想将文本“信息”居中。尝试了align =“center”但没有工作
我的代码正确吗?
<table border="1" width="100%" cellspacing="10">
<tr>
<th>column1</th>
<th>column2</th>
<th bgcolor="#4F81BD"><strong><font size="5" color="white" face="calibri" align="center">Information</font><strong></th>
</tr>
</table>
[编辑] 这是我根据您的回答构建的代码。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title</title>
<style type="text/css">
.centerText{
text-align: center;}
</style>
</head>
<table border="0" width="100%" cellspacing="10">
<tr>
<th></th>
<th></th>
<th class="centerText" bgcolor="#4F81BD"><strong><font size="5" color="white" face="calibri" >Information</font><strong></th>
</tr>
</table>
</body>
</html>
这是处理这个问题的正确方法吗?
how to center the
I would like to center the text "Information". Tried the align="center" but didn't work
Is my code correct?
<table border="1" width="100%" cellspacing="10">
<tr>
<th>column1</th>
<th>column2</th>
<th bgcolor="#4F81BD"><strong><font size="5" color="white" face="calibri" align="center">Information</font><strong></th>
</tr>
</table>
[EDIT] Here is the code I have built thanks to your answsers.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title</title>
<style type="text/css">
.centerText{
text-align: center;}
</style>
</head>
<table border="0" width="100%" cellspacing="10">
<tr>
<th></th>
<th></th>
<th class="centerText" bgcolor="#4F81BD"><strong><font size="5" color="white" face="calibri" >Information</font><strong></th>
</tr>
</table>
</body>
</html>
Is this the right way to handle this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在您的代码中,您将
align="center"
放入strong
内的font
标记。所有这些元素都是内联的,并不适合所有单元格宽度。要将其居中对齐,您需要将此类属性放置到th
标记中,或将string
和font
标记的显示更改为display :block
以适应所有宽度。最简单的方法是在 CSS 中:
PS 更好的方法是将所有内联样式移动到 CSS 文件中。
In your code you putting
align="center"
to thefont
tag inside of thestrong
. All of these elements are inline and doesn't fits all the cell width. To align it on center you need to put such attribute to theth
tag or change displaying of thestring
andfont
tags todisplay:block
to fit all the width.The simplest way to do this is in CSS:
P.S. Better way is to move all of your inline style to CSS files.
使用
text-align:center;
请参阅jsfiddle 上的实时示例
[编辑] 请注意,您应该使用其他用户指出的类或元素在 CSS 中实现这些样式
Use
text-align:center;
see this live example on jsfiddle
[EDIT] Note that you should implement these styles within your CSS with classes or elements as pointed out by fellow users
尝试使用CSS。
Try using CSS.
标签已弃用 它的使用被认为是一个非常糟糕的主意。请改用 CSS。
标记来使文本变为粗体也不是特别有用,尤其是在
元素内。
已经表明文本很重要,因为它是表格列的标题。在许多浏览器中,文本已在
中变为粗体
text-align: center
<font>
tag is deprecated and it's use is considered a very bad idea. Use CSS instead.<strong>
tag just to get the text to be bold is also not particularly useful, especially inside a<th>
element. The<th>
already indicates that the text matters because it's the header of a table column. In many browsers, the text is already made bold in<th>
stext-align: center
尝试这个
Trying this