..... But alignment is not a more...">

Center Alignment DIV

I have a div that has all the content centered:

<div align="center">
   <table><tr><td>.....

But alignment is not a more reliable attribute. So, I changed the class or style:

<div style="text-align:center;">

But this is not the same as before. Now the table is aligned to the left, not to the center. The obvious alignment of the text is not equivalent to the attribute of the old center. How to write a style to achieve the same functionality as before, with the center attribute?

+4
source share
6 answers

Just use margin: 0 autoon tableto center it.

See HERE

+3
source

, :

table {
 margin: 0 auto;
} 

, , , .

+2

,

CSS:

table.center {
              margin-left:auto; 
              margin-right:auto;
             }

:

<table class="center">
...
</table>
+1

, ?

.

. , ().

Edit:

@mattytommo .

+1

,

<table align="center">

div.

0

: -

div{
   width:90%;
   margin:0 auto;
   text-align:center;
}

<div style="width:90%;margin:0 auto;text-align:center">
   <table>
       <thead>
           <tr>
               <th>header</th>
           </tr>
       </thead>
       <tbody>
           <tr>
               <td>data</td>
           </tr>
       </tbody>
   </table>
</div
0

All Articles