Reputation: 77
I'm new to HTML & CSS. I made multiple tables and wish to display them all on one line inside a box. I tried the following but this doesn't seem to work. Can someone please fix this? This is my CSS code:
#content2{
margin: 30px 0;
background: white;
padding: 20px;
clear: both;
box-shadow: 0px 1px 1px #999;
text-align: center;
overflow:hidden;
}
table{
margin-right: auto;
margin-left: auto;
float:left;
}
td,th{
padding: 20px;
}
The HTML should be correct.
Upvotes: 1
Views: 1615
Reputation: 10603
You have a few options that im aware of.
1 . If you want it pure CSS and "dynamic" (i.e. you dont know the width beforehand) you can set the table to display: inline-block
and remove your float. This works in chrome, but you may have issues with IE, especially older versions.
2 . If you know the width then set an inner content div with that width, and margin:auto
it.
3 . if you don't know the width, but your happy to use JS, then do the same as above, but calculate the width in JS (i use jQuery as its what im used to, but you could use raw JS)
Upvotes: 0