dsjxgu4759 2014-06-03 15:26
浏览 266
已采纳

display:不使用表的table-cell和table-row替代方法(dompdf的问题)

I am using the dompdf library to generate a PDF but can't use large tables as the dompdf library does not support it. So I changed the tables to use span tags and styled the elements with display: table-cell & display: table-row.

The problem is that dompdf is still treating those span tags as a table (because of the styles).

Question: Are there alternative css styles I can use to get the same look & feel WITHOUT using display: table-cell & display: table-row and without using tables?

Here is my code:

HTML:

<span class="table">
    <span class="tr">
        <span class="th h2">Request Information</span>
    </span> 
    <span class="tr">
        <span class="td">Quote #</span>
        <span class="td">sdfsdfsdfsf</span>
    </span> 
    <span class="tr">
        <span class="td">Project Number</span>
        <span class="td">sdfsdfsdfsd</span>
    </span> 
    <span class="tr">
        <span class="td">Account Manager</span>
        <span class="td">khksjksjhdf</span>
    </span> 
    <span class="tr">
        <span class="td">Customer</span>
        <span class="td">ljsljflksjd</span>
    </span> 
    <span class="tr">
        <span class="td">Customer Location</span>
        <span class="td">
            123 Fake Street<br>
            City, State ZIPCode                 
        </span>
    </span> 
    <span class="tr">
        <span class="td">Customer Contact</span>
        <span class="td">lsjdlfkjslkjdfs</span>
    </span> 
    <span class="tr">
        <span class="td">Date Submitted</span>
        <span class="td">sdfsdfgdfg</span>
    </span> 
    <span class="tr">
        <span class="td">Date Approved</span>
        <span class="td">N/A</span>
    </span>
</span>

CSS:

span {
    width: 72% !important;
    padding: 5px 0px 5px 0px;
    /*padding-bottom: 9px;*/
    /*border: 1px solid Black;*/
}
span.table {
    /*border-collapse: collapse;*/
    /*display: table;*/
}
span .td {
    border: none !important;
    background: White !important;
    display: table-cell;
    padding-left: 10px;
    font-size: 16px;
    margin-bottom: 30px;
    border:none !important;
}
span .tr {
    display: table-row;
    border: 1px solid Black;
    padding: 2px 2px 2px 5px;
    background-color: #f5f5f5;
}
span .th {
    text-align: left;
    font-weight: bold;
}

jsFiddle: http://jsfiddle.net/Mn7GH/

  • 写回答

1条回答 默认 最新

  • drq22639 2014-06-03 16:42
    关注

    You can simulate a table playing with the display, width, and float of the span tags (although it would be better using div).

    The idea of the table is having a block that will hold everything:

    span.table {
        display:block;
        height:auto;
        overflow:auto;
        border:1px solid black;
    }
    

    It has display block (use a div if possible), you want height:auto and overflow:auto so it will grow along with the floating elements.

    Then the row will be similar:

    span.tr {
        display:block;
        height:auto;
        overflow:auto;
        border: 1px solid Black;
    }
    

    It will take 100% of the width automatically because of the display:block, so we are good. The height and overflow values are auto for the same reason as the table (maybe it would only be needed in the tr).

    And finally the cells. For the td, we will set up a display:inline-block and make them float to the left:

    span.td {
        border:none !important;
        float:left;
        display:inline-block;
        width:50%;
    }
    

    The only thing to take into account is that you may want different widths for different columns, in that case you will have to define specific classes with the widths. (notice that for an ideal visualization, table and tr must have padding:0 and margin:0, and the sum of all the widths must be equal to 100%)

    You can see an example using your html code and updating your css here: http://jsfiddle.net/Mn7GH/3/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私