CSS way to horizontally align table
Steven is right, in theory:
the “correct” way to center a table using CSS. Conforming browsers ought to center tables if the left and right margins are equal. The simplest way to accomplish this is to set the left and right margins to “auto.” Thus, one might write in a style sheet:
table
{
margin-left: auto;
margin-right: auto;
}
But the article mentioned in the beginning of this answer gives you all the other way to center a table.
An elegant css cross-browser solution:
This works in both MSIE 6 (Quirks and Standards), Mozilla, Opera and even Netscape 4.x without setting any explicit widths:
div.centered
{
text-align: center;
}
div.centered table
{
margin: 0 auto;
text-align: left;
}
<div class="centered">
<table>
…
</table>
</div>
How to center a div horizontally in a table using CSS
try below code..
do it in every tag
And add below code in your css
<td>
<div class="socicon">
<div class="social_icon">
<i class="fa fa-google-plus" aria-hidden="true"></i>
</div>
</div>
</td>
.socicon {
margin: 0 auto;
text-align: center;
width: 57%; // you have to adjust width as your requirement
}
How do I horizontally align vertical text in a table with CSS?
It seems to be a bug on Firefox that you can fix by adding an extra element where you apply the writing-mode
td {
text-align: center;
}
td span {
writing-mode: vertical-rl;
vertical-align:top; /* remove bottom whitespace */
}
td,
th {
border: 1px solid black;
}
<table>
<tbody>
<tr>
<th>This is my heading</th>
</tr>
<td>
<span>しょうがない</span>
</td>
</tbody>
</table>
Align two tables horizontally HTML/CSS
You can use valign = top
.
<table width=100%>
<tr>
<td valign="top"><table1 code goes here>
</td>
<td valign="top"><table2 code goes here>
</td>
</tr>
</table>
How to position a table at the center of div horizontally & vertically
Centering is one of the biggest issues in CSS. However, some tricks exist:
To center your table horizontally, you can set left and right margin to auto:
<style>
#test {
width:100%;
height:100%;
}
table {
margin: 0 auto; /* or margin: 0 auto 0 auto */
}
</style>
To center it vertically, the only way is to use javascript:
var tableMarginTop = Math.round( (testHeight - tableHeight) / 2 );
$('table').css('margin-top', tableMarginTop) # with jQuery
$$('table')[0].setStyle('margin-top', tableMarginTop) # with Mootools
No vertical-align:middle
is possible as a table is a block and not an inline element.
Edit
Here is a website that sums up CSS centering solutions: http://howtocenterincss.com/
Center a table horizontally in a div
Tables are block level elements. You can set the width
of the table and set margin: auto
If the width
varies you may be able to use a percentage or a combination of width
and min/max-width
.
Horizontally align table cell element
Using correct display
:
- Using
margin: auto
anddisplay: block
for<a>
. - Using
display: inline-block
for<img />
Code:
.prod-img {
display: block;
margin: 20px; border:1px solid black;
text-align: center;
vertical-align: middle;
}
.prod-img a {
max-width: 170px;
height: 150px;
line-height: 150px;
display: block;
vertical-align: middle;
margin: auto;
}
.prod-img img {
width: auto;
max-width: 100%;
height: auto;
max-height: 100%;
max-height: calc(100% - 30px);
margin: 0 auto;
vertical-align: middle;
}
Preview:
Fiddle: http://jsfiddle.net/1zLLasfw/
Related Topics
Table Overflowing Outside of Div
How Does Stackoverflow Make Its Tag Input Field
How to Display a Range Input Slider Vertically
Offline iOS Web App: Loads My Manifest, But Doesn't Work Offline
Why Isn't My Margin Working with Position: Fixed
Mobile Website "Whatsapp" Button to Send Message to a Specific Number
Getting Youtube.Com to Load in Iframe
CSS Zigzag Border with a Textured Background
How to Fix "Insecure Content Was Loaded Over Https, But Requested an Insecure Resource"
HTML Submit-Button: Different Value/Button-Text
R: Saving Multiple HTML Widgets Together
How to Center Content in a Bootstrap Column
Why Is a Trailing Punctuation Mark Rendered at The Start with Direction:Rtl