I have this table I want to align in the middle of the webpage. But it is stuck on the left hand side of the page. This is my code:
<table class="tableOne" align="center">
<tr >
<img src='Images/Header.png' />
</tr>
</table>
What is wrong with the code? I just need the table in the middle of the page.
This is because text-align:center only affects inline elements, and <aside> is not an inline element by default. It is a block-level element. To align it, we will have to use something other than text-align , or turn it into an inline element.
To center align text in table cells, use the CSS property text-align. The <table> tag align attribute was used before, but HTML5 deprecated the attribute. Do not use it. So, use CSS to align text in table cells.
Select the text that you want to center, and then click Paragraph on the Format menu. On the Indents and Spacing tab, change the setting in the Alignment box to Centered, and then click OK.
Don't use align="center"
it's not a standard property. You could opt use CSS instead.
To center the table within its container using margin:auto
.
<style>
.tableOne {
margin:auto;
}
</style>
To center the text within the table cell, use text-align:center
.
<style>
.tableOne td {
text-align:center;
}
</style>
Also you didn't add a <td>
inside the <tr>
. You should always make sure the contents of a table cell is within a <td>
so your HTML is valid.
<table class="tableOne">
<tr>
<td>
<img src='Images/Header.png' />
</td>
</tr>
</table>
As a side note, if you're only using the table to center your image you should get rid of the table. This could be replaced by a simple div.
HTML
<div class="center-me">
<img src='Images/Header.png' />
</div>
CSS
.center-me {
text-align:center;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With