[英]margin in css doesn't work
I have Table and I want to put it in the middle of the page. 我有表格,我想把它放在页面中间。 If I set align attribute to center, it works but I want to do that with CSS.
如果我将align属性设置为center,它可以工作,但是我想使用CSS做到这一点。 Here is my CSS:
这是我的CSS:
center vorder, td
{
border-color:Blue;
border-style:double;
color:#8A2BE2F;
margin-left:auto;
margin-left:auto;
margin-right:auto;
}
and this is my table code: 这是我的表代码:
<table class="center vorder" >
<tr><td colspan="4">mittige Tabelle</td></tr>
<tr><td>Element 0 0</td><td>Element 0 1</td><td>Element 0 2</td><td>Element 0 3</td></tr>
<tr><td>Element 1 0</td><td>Element 1 1</td><td>Element 1 2</td><td>Element 1 3</td></tr>
<tr><td>Element 2 0</td><td>Element 2 1</td><td>Element 2 2</td><td>Element 2 3</td></tr>
</table>
Thank you for your help. 谢谢您的帮助。
Your CSS syntax is off. 您的CSS语法已关闭。
table.center
{
margin-left:auto;
margin-right:auto;
}
td {
border-color:Blue;
border-style:double;
color:#8A2BE2F;
}
you missing syntax, need to prefix class with "." 您缺少语法,需要在类的前面加上“”。
.center.vorder, td
{}
Refer working fix http://jsbin.com/azoxes/1/edit 请参阅工作修补程序http://jsbin.com/azoxes/1/edit
You sould use .
您可以使用
.
for class in CSS: 对于CSS中的类:
.center.vorder
{
border-color: blue;
border-style: double;
color: #8A2BE2F;
margin: 0 auto;
}
If you want center the td's text you shuld use this: 如果要使td的文本居中,则应使用以下命令:
td
{
text-align: center;
}
From that code, your css is not even getting used. 通过该代码,您的css甚至没有被使用。 It should be something like:
应该是这样的:
.center.vorder, td
or 要么
.center.vorder td
..depending on what you want to target. ..取决于您要定位的目标。
Also you have margin-left: auto
twice, so remove one. 此外,您还有
margin-left: auto
两次,因此删除一个。 You can do it in one line like so: 您可以像这样一行来完成:
margin: 0 auto;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.