douxiluan6555 2015-02-16 14:55
浏览 79
已采纳

如何防止PHP推送的HTML表超过页面的长度

I am still a novice and would appreciate any assistance you can provide.

I am trying to prevent an HTML table from exceeding the length of the page. I am currently parsing a csv with PHP and looping the array information into an HTML table.

The table is to be shown on a static 1080p screen so the table itself needs to resize by shrinking cells instead of going off the page horizontally or vertically. I dont mind how squashed the cells become as they are colour coded with CSS.

I have too many lines of code to post here so I will just post my CSS style code which I have attempted to use to contain my table.

  <style>

    html,body {
        background-color: #F4F4F4
        margin: 0;
        padding: 0;
        height: 100%;
        border: 0;
    }

    table{
        height:100%;
        width:100%;
        overflow: hidden;
        white-space: nowrap;
    }

    td {
        border: 1px solid black;
        resize: both;
        overflow: hidden;
    }

    th {
        resize: both;
        overflow: auto;
    }

</style>

I have tried different variations of the above to no avail e.g. overflow settings, resize settings etc this is just my current test.

I do not care whether I have to use HTML, CSS, Javascript, JQuery or PHP for this. I would rather not have to completely start over however.

  • 写回答

2条回答 默认 最新

  • duanpu1111 2015-02-16 17:18
    关注

    Try to include this for your tags:

    td.wordbreak {
        word-break: break-all;
        width: NNNpx;
    }
    

    This should sort the problem of cells spiting out your table horizontally. Replace the NNN by a number in pixels, that could be a fraction of the total you need.

    So let's say you had only 2 columns, it would be:

    table {
    
      table-layout: fixed;   width: 100%;
    
    }
    
    td
    {   
       word-break: break-all;   
       width: 540px; 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭