92

デスクトップではテーブルが正常に表示されますが、モバイルバージョンを表示しようとすると、テーブルがモバイルデバイスの画面に対して広すぎます。レスポンシブレイアウトを使用しています。

モバイルビューのテーブル幅を設定するにはどうすればよいですか?Bootstrapを使用してモバイルビューに表形式のデータを表示する他の方法はありますか?

4

4 に答える 4

5

ブートストラップ内のすべてのテーブルは、コンテナに応じて伸縮します。テーブルを.span要素内に配置して、サイズを制御できます。このSOの質問はあなたを助けるかもしれません

Twitter Bootstrap テーブルの幅が常に 100% になるのはなぜですか?

于 2013-02-13T03:45:40.873 に答える
2

ほぼ1か月間調査した後、私のWebサイトで非常に美しく100%完全に機能する以下のコードを見つけました。プレビューでどのように機能しているかを確認するには、リンクから確認できます。https://www.jobsedit.in/state-government-jobs/

https://www.jobsrob.in/category/central-government-jobs/

CSSコード-----

@media only screen and (max-width: 500px)  {
    .resp table  { 
        display: block ; 
    }   
    .resp th  { 
        position: absolute;
        top: -9999px;
        left: -9999px;
        display:block ;
    }   
     .resp tr { 
    border: 1px solid #ccc;
    display:block;
    }   
    .resp td  { 
        /* Behave  like a "row" */
        border: none;
        border-bottom: 1px solid #eee; 
        position: relative;
        width:100%;
        background-color:White;
        text-indent: 50%; 
        text-align:left;
        padding-left: 0px;
        display:block;      
    }
    .resp  td:nth-child(1)  {
        border: none;
        border-bottom: 1px solid #eee; 
        position: relative;
        font-size:20px;
        text-indent: 0%;
        text-align:center;
}   
    .resp td:before  { 
        /* Now like a table header */
        position: absolute;
        /* Top/left values mimic padding */
        top: 6px;
        left: 6px;
        width: 45%; 
        text-indent: 0%;
        text-align:left;
        white-space: nowrap;
        background-color:White;
        font-weight:bold;
    }
    /*
    Label the data
    */
    .resp td:nth-of-type(2):before  { content: attr(data-th) }
    .resp td:nth-of-type(3):before  { content: attr(data-th) }
    .resp td:nth-of-type(4):before  { content: attr(data-th) }
    .resp td:nth-of-type(5):before  { content: attr(data-th) }
    .resp td:nth-of-type(6):before  { content: attr(data-th) }
    .resp td:nth-of-type(7):before  { content: attr(data-th) }
    .resp td:nth-of-type(8):before  { content: attr(data-th) }
    .resp td:nth-of-type(9):before  { content: attr(data-th) }
    .resp td:nth-of-type(10):before  { content: attr(data-th) }
}

HTML コード --

<table>
<tr>
<td data-th="Heading 1"></td>
<td data-th="Heading 2"></td>
<td data-th="Heading 3"></td>
<td data-th="Heading 4"></td>
<td data-th="Heading 5"></td>
</tr>
</table>
于 2020-11-14T16:00:18.570 に答える