简体   繁体   English

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

[英]display: table-cell & table-row alternative without using tables (problems with 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. 我使用dompdf库生成PDF但不能使用大表,因为dompdf库不支持它。 So I changed the tables to use span tags and styled the elements with display: table-cell & display: table-row . 所以我更改了表格以使用span标签,并使用display: table-celldisplay: table-row设置元素样式。

The problem is that dompdf is still treating those span tags as a table (because of the styles). 问题是dompdf仍然将这些span标签视为一个表(因为样式)。

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? 问题:我是否可以使用其他css样式来获得相同的外观和感觉而不使用display: table-celldisplay: table-row而不使用表格?

Here is my code: 这是我的代码:

HTML: 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: 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/ jsFiddlehttp//jsfiddle.net/Mn7GH/

You can simulate a table playing with the display , width , and float of the span tags (although it would be better using div). 您可以模拟使用span标签的显示宽度浮动的表格(尽管使用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. 它有显示块(如果可能的话使用div),你想要height:autooverflow:auto所以它会随浮动元素一起增长。

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. 由于display:block ,它将自动占用宽度的100%,所以我们很好。 The height and overflow values are auto for the same reason as the table (maybe it would only be needed in the tr). 高度和溢出值是自动的,原因与表相同(可能只在tr中需要)。

And finally the cells. 最后是细胞。 For the td, we will set up a display:inline-block and make them float to the left: 对于td,我们将设置一个显示:inline-block并使它们向左浮动:

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%) (请注意,对于理想的可视化,table和tr必须具有填充:0和margin:0,并且所有宽度的总和必须等于100%)

You can see an example using your html code and updating your css here: http://jsfiddle.net/Mn7GH/3/ 您可以在此处查看使用html代码并更新css的示例: http//jsfiddle.net/Mn7GH/3/

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

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