【问题标题】:"word-wrap:break-word" doesn't work when generating PDF with SpraedPDFBundle使用 SpraedPDFBundle 生成 PDF 时,“word-wrap:break-word”不起作用
【发布时间】:2015-10-08 17:56:09
【问题描述】:

我试图打破<td> 中的文本。我尝试了一些 poroposed 的解决方案,但似乎它们都不起作用。

可能的重复: Word-wrap

我想断开一个大链接。这是我的代码:

<div style="padding-top: 250px;  margin-right: 25px;">
        <table style="table-layout:fixed; width:700px;">
            <col width="300">
            <col width="10">
            <col width="10">
            <col width="10">
            <col width="10">
            <thead>
                <tr>
                    <th class="desc">Link</th>
                    <th class="unit">Price</th>
                    <th class="qty">Amount</th>
                    <th class="service">TVA</th>
                    <th class="total">TOTAL</th>
                </tr>
            </thead>
            <tbody>
                    <tr>
                        <td class="desc" style="overflow:hidden; word-wrap: break-word;
                            word-break: break-all;">Link</td>
                        <td >price</td>
                        <td >amount</td>
                        {% if oProd.tva %}
                            <td>tva%</td>
                        {% else %}
                            <td>TVA non existante</td>
                        {% endif%}
                        <td>inal_price</td>
                        {% set total = total + final_price%}
                    </tr>
                {% endfor %}
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="2"></td>
                    <td colspan="2">Prix final</td>
                    <td>{{ total }}</td>
                </tr>
            </tfoot>
        </table>
    </div>

现在这是我的 desc 的 CSS:

    .service .desc h4 {
    font-size: 22px;
    line-height: 25px;
}
.service .desc {
    padding: 0 15px;
    overflow: hidden;
}
table .desc {
    text-align: left;
    background: #D0D0D0;
}

【问题讨论】:

  • 您能否发布 .desc 的 CSS,您可以尝试使用 60% 或 300em 等指定列宽。另外说明,这可能会提高浏览器兼容性 td { white-space: pre; /* CSS 2.0 */ white-space: pre-wrap; /* CSS 2.1 */ white-space: pre-line; /* CSS 3.0 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ white-space: -moz-pre-wrap; /* Mozilla */ white-space: -hp-pre-wrap; /* HP Printers */ word-wrap: break-word; /* IE 5+ */ } source
  • 试试这个:table tr td, table tr th { page-break-inside: avoid; }
  • @Mousey 你觉得我是不是有点过分了?
  • @Matteo 对我不起作用。还有其他建议吗?
  • 嗨@BesbesRiadh,对不起,我使用knplabs/knp-snappy-bundle,我的评论是解决同一问题但使用该捆绑包的解决方案....

标签: html css symfony pdf twig


【解决方案1】:

@Besbes Riadh 我发布的代码将使word-wrap: break-word 适用于不同的浏览器和不同版本的CSS。它可以添加到 CSS 的末尾。 Explanation and source

【讨论】:

  • 我现在确实回到了这个问题,您的解决方案运行良好!现在我正在尝试让我的网站具有响应性,我希望这不会让我的字段看起来很拥挤。
猜你喜欢
  • 2011-04-29
  • 2012-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-08
  • 2013-06-13
相关资源
最近更新 更多