简体   繁体   English

如何制作响应式表头?

[英]How to make a responsive table header?

I have this table, but elements at last column don't fit the entire table when display is in a big size. 我有这个表,但是当显示的大小时,最后一列的元素不适合整个表。 What am I doing wrong? 我究竟做错了什么?

Large

在此输入图像描述

Medium 介质

在此输入图像描述

Small

在此输入图像描述

I have 我有

<div class="panel-body">
  <table class="table mb30" class="display" cellspacing="0" width="100%">
    <thead>
      <tr>
        <th width="5%">#</th>
        <th width="30%">Site Name</th>
        <th width="40%">Site URL</th>
        <th width="25%">Action</th>
      </tr>
    </thead>

    <tbody>
      <tr>
        <td>1</td>
        <td>Name</td>
        <td>URL</td>
        <td>Action</td>
      </tr>

    </tbody>
  </table>
</div>

I've put together a fiddle 我把小提琴放在一起

You need <meta name="viewport" content="width=device-width"> in the header. 标题中需要<meta name="viewport" content="width=device-width">

then use: 然后使用:

 @media screen and (max-width : 725px ){ #id {} .class {} } 

change max-width to what you want. 将max-width更改为您想要的。

Don't give the action column a percentage width. 不要给动作列指定百分比宽度。 If you give table headers a percentage that adds up to the total and leave out a column, all the % based columns will take up as much room as they have available. 如果您为表格标题提供一个百分比,该百分比可以累计总数并且不会显示任何列,则所有基于%的列将占用尽可能多的空间。

https://jsfiddle.net/pkjbpsr7/1/ https://jsfiddle.net/pkjbpsr7/1/

For example: 例如:

  <tr>
    <th width="5%">#</th> <!-- This column and the next two will fill the space available. -->
    <th width="30%">Site Name</th>
    <th width="65%">Site URL</th>
    <th>Action</th> <!-- This one will just chill off to the side and only take up as much room as it has width -->
  </tr>

If you need it to take up a certain amount of space, you can always give it a min-width: 如果你需要它占用一定的空间,你总是可以给它一个最小宽度:

https://jsfiddle.net/pkjbpsr7/4/ https://jsfiddle.net/pkjbpsr7/4/

    <th width="5%">#</th>
    <th width="30%">Site Name</th>
    <th width="65%">Site URL</th>
    <th id="min-width">Action</th> <!-- This will take up 100px per it's min-width -->

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM