Reputation: 163
I'm trying to add some margin to my table. Padding and border work but margin doesn't.
th {
border: 1px solid black;
margin: 10px;
padding: 10px;
}
<table id="Expon">
<tr>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
</table>
Upvotes: 2
Views: 344
Reputation: 7534
Use border-spacing to space between your cells, instead of using margin.
th{
border: 1px solid black;
padding: 10px;
}
table{
border-spacing: 10px;
}
<table id="Expon">
<tr>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
</table>
Upvotes: 0
Reputation: 131
if you want to add margin you need to add table cellspacing="10" here is my code to test , try this code....
<html>
<head>
<style>
th {
border: 1px solid black;
padding: 10px;
}
</style>
</head>
<body>
<table id="Expon" cellspacing="10">
<tr>
<th>gfhd</th>
<th>dfgh</th>
<th>gfh</th>
</tr>
<tr>
<th>gfh</th>
<th>fgh</th>
<th>gfh</th>
</tr>
<tr>
<th>fgdh</th>
<th>gfh</th>
<th>fgh</th>
</tr>
</table>
</body>
</html>
Upvotes: 1
Reputation: 519
Try to define each margin side:
margin-top: 10px;
margin-bottom: 10px;
margin-right: 10px;
margin-left: 10px;
You have to define each side of the margin. If you need more help with margins, refer to this link: https://www.w3schools.com/css/css_margin.asp
Upvotes: 0
Reputation: 1970
Similar to cell-spacing, in css you can use border-spacing
along with border-collapse: separate
properties, applied to the parent table
tag
table {
border-spacing: 10px;
border-collapse: separate;
}
th {
border: 1px solid black;
margin: 10px;
padding: 10px;
}
<table id="Expon">
<tr>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
</table>
Upvotes: 0