How can I center three tables in a div?

后端 未结 2 1582
暗喜
暗喜 2021-01-28 07:22

I am struggling with a CSS problem. I have three tables and I need them to center in a div. I have tried floating, text-align:center and anything else came in mind but I just ca

相关标签:
2条回答
  • 2021-01-28 08:14

    Not sure why tables are being used. Bootstrap was mentioned, and is the right idea -- Maybe a bit of overkill, you just need a bit of the grid. Stealing some from Bootstrap:

    http://jsfiddle.net/U9Reg/

    <style>
            div {
            display: block;
            }
            p {
            text-align: center;
            }
            .row {
    margin-left: -15px;
    margin-right: -15px
    }
    
    .col-md-4 {
       position: relative;
       min-height: 1px;
       padding-right: 15px;
       padding-left: 15px;
       width: 30%;
       float: left;
    }
    
    .centerPix {
    margin: 0 auto;
    display: block;
    height: 65px;
    width: 65px;
    }</style>
    
    <div class="row">
    <div class="col-md-4">
    <img class="centerPix" src="http://alimos.topgreekgyms.gr/wp-content/uploads/2013/12/clock.png"/><p>Here is some text.</div>
    <div class="col-md-4">
    <img class="centerPix" src="http://alimos.topgreekgyms.gr/wp-content/uploads/2013/12/stats.png"/>
    <p>Here is some text</p></div>
    <div class="col-md-4">
    <img class="centerPix" src="http://alimos.topgreekgyms.gr/wp-content/uploads/2013/12/zigaria2.png"/>
    <p>Here is some text.</p></div>
    </div>
    
    0 讨论(0)
  • 2021-01-28 08:15

    Fiddle: http://jsfiddle.net/ZssZw/

    <div style="margin:0 auto;width:91%;">
    
     <table>
        <tr>
           <td><img height="35" width="32" src="http://alimos.topgreekgyms.gr/wp-content/uploads/2013/12/clock.png"/></td>
           <td><img height="35" width="32" src="http://alimos.topgreekgyms.gr/wp-content/uploads/2013/12/stats.png"/></td>
           <td><img height="35" width="32" src="http://alimos.topgreekgyms.gr/wp-content/uploads/2013/12/zigaria2.png"/></td>
        </tr>
         <tr>
             <td style="text-align:center;">55'</td> 
    
           <td style="text-align:center;">4-5</td> 
           <td style="text-align:center;">500</td> 
         </tr>
    
    
         </table>
    
       </div>
    
    0 讨论(0)
提交回复
热议问题