bootstrap responsive table content wrapping

前端 未结 10 1729
南旧
南旧 2020-12-24 11:10

I have HTML similar to this:

    
相关标签:
10条回答
  • 2020-12-24 11:51

    EDIT

    I think the reason that your table is not responsive to start with was you did not wrap in .container, .row and .col-md-x classes like this one

    <div class="container">
       <div class="row">
         <div class="col-md-12">
         <!-- or use any other number .col-md- -->
             <div class="table-responsive">
                 <div class="table">
                 </div>
             </div>
         </div>
       </div>
    </div>
    

    With this, you can still use <p> tags and even make it responsive.

    Please see the Bootply example here

    0 讨论(0)
  • 2020-12-24 11:52

    Fine then. You can use CSS word wrap property. Something like this :

    td.test /* Give whatever class name you want */
    {
    width:11em; /* Give whatever width you want */
    word-wrap:break-word;
    }
    
    0 讨论(0)
  • 2020-12-24 11:52

    use it in css external file.

    .td-table
    {
    word-wrap: break-word;
    word-break: break-all;  
    white-space: normal !important;
    text-align: justify;
    }
    
    0 讨论(0)
  • 2020-12-24 11:59

    The behaviour is on purpose:

    Create responsive tables by wrapping any .table in .table-responsive to make them scroll horizontally on small devices (under 768px). When viewing on anything larger than 768px wide, you will not see any difference in these tables.

    Which means tables are responsive by default (are adjusting their size). But only if you wish to not break your table's lines and add scrollbar when there is not enough room use .table-responsive class.

    If you take a look at bootstrap's source you will notice there is media query that only activates on XS screen size and it sets text of table to white-space: nowrap which causes it to not breaking.

    TL;DR; Solution

    Simply remove .table-responsive element/class from your html code.

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