Centering text in a table in Twitter Bootstrap

后端 未结 10 1787
予麋鹿
予麋鹿 2020-12-12 15:48

For some reason, The text inside the table still is not centered. Why? How do I center the text inside the table?

To make it really Clear: For example, I want "L

相关标签:
10条回答
  • 2020-12-12 16:23

    I had the same problem and a better way to solve it without using !important was defining the following in my CSS:

    table th.text-center, table td.text-center { 
        text-align: center;
    }
    

    That way the specifity of the text-center class works correctly in tables.

    0 讨论(0)
  • 2020-12-12 16:25

    One of the main feature of Bootstrap is that it alleviates the use of !important tag. Using the above answer would defeat the purpose. You can easily customise bootstrap by modifying the classes in your own css file and linking it after including the boostrap css.

    0 讨论(0)
  • 2020-12-12 16:26

    You can make td's align without changing the css by adding a div with a class of "text-center" inside the cell:

        <td>
            <div class="text-center">
                My centered text
            </div>
        </td>
    
    0 讨论(0)
  • 2020-12-12 16:31

    I think who the best mix for html & Css for quick and clean mod is :

    <table class="table text-center">
    <thead>
            <tr>                    
            <th class="text-center">Uno</th>
            <th class="text-center">Due</th>
            <th class="text-center">Tre</th>
            <th class="text-center">Quattro</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>2</td>
            <td>3</td>
            <td>4</td>
        </tr>
    </tbody>
    </table>
    

    close the <table> init tag then copy where you want :) I hope it can be useful Have a good day w stackoverflow

    p.s. Bootstrap v3.2.0

    0 讨论(0)
  • 2020-12-12 16:36
    <td class="text-center">
    

    and fix .text-center in bootstrap.css:

    .text-center {
        text-align: center !important;
    }
    
    0 讨论(0)
  • 2020-12-12 16:38

    If it's just once, you shouldn't alter your style sheet. Just edit that particular td:

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

    Cheers

    0 讨论(0)
提交回复
热议问题