我有这个css:
.tableheader {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
}
.text1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
background-color: #fff;
}
......
<table class = bordergray cellspacing=1 cellpadding=5>
<tr class = tableheader valign="bottom">
<caption>Shining Star Award</caption>
<td>Month</td>
<td>employee first name</td>
<td>employee last name</td>
<td>stars<br/></td>
</tr>
<cfoutput query="shiningStar">
<tr class = text1>
<td>#</td>
<td>#</td>
<td>#</td>
<td>#</td>
</tr>
</cfoutput>
</table>
我希望桌子出现在页面的中央,还是不在左下角? 我该怎么做?
答案 0 :(得分:2)
使用margin: 0 auto
示例:
.bordergray{
margin: 0 auto;
}
http://jsfiddle.net/vDzx4/
答案 1 :(得分:1)
这是你想要的吗?
您的HTML标记无效 - &gt; classes
应引用class="someclass"
要将页面中的元素居中,您应该为其fixed width
并使用margin:0 auto
。
<强> HTML 强>
<table class="bordergray" cellspacing="1" cellpadding="5">
<tr class="tableheader" valign="bottom">
<caption>Shining Star Award</caption>
<td>Month</td>
<td>employee first name</td>
<td>employee last name</td>
<td>stars<br/></td>
</tr>
<cfoutput query="shiningStar">
<tr class="text1">
<td>#</td>
<td>#</td>
<td>#</td>
<td>#</td>
</tr>
</cfoutput>
</table>
<强> CSS 强>
.bordergray{
width:300px; /*fixed width for aligning the element center*/
border:1px solid red;
margin:0 auto; /*centers the element*/
}
.tableheader {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
}
.text1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
background-color: #fff;
}
答案 2 :(得分:1)