简体   繁体   English

使用@media 打印在第二页上剪切的 CSS/HTML 打印表

[英]CSS/HTML Printing Table Cut on 2nd page using @media print

Im struggling on my TD when it has 2nd page continues, border always cut when entering the 2nd page does any one has the idea to solve this kind of problem using CSS @media print?当它有第二页时,我在我的 TD 上挣扎,进入第二页时边框总是被切断 有没有人有想法使用 CSS @media 打印来解决这种问题? i tried using page-break-inside but it didnt solve my problem issue please help我尝试使用 page-break-inside 但它没有解决我的问题请帮助

CSS CSS

 @media print {
    body {
        display: table;
        padding-bottom: 40px;
        height: auto;
        font-size: 5pt;
        margin-top: 20px;
    }

    .table-print {
        font-family: arial, sans-serif;
        width: 100%;
        margin-left: 30px;
        font-size: 9pt;
    }

    table { 
        page-break-inside:auto 
    }

    td  { 
        page-break-inside:avoid; 
        page-break-after:auto 
    }}

Laravel Blade: Laravel 刀片:

<table class="table-print">
    <tr>
        <h1>Company.</h1>
        <h1>Item Summary</h1>
        @foreach($c_name as $cc) 
        <h1>{{{$cc->description}}}</h1>
        <h1>{{{$cc->address}}}</h1>
        @endforeach
    </tr>
    <tr>
        <td class="label-bold">Item</td>
        <td class="label-bold">Quantity</td>
        <td class="label-bold">Unit</td>
        <td class="label-bold">Date of Return</td>
        <td class="label-bold">Plate#</td>
        <td class="label-bold">Reference no.</td>
        <td class="label-bold">Remarks</td>
    </tr>

    @foreach($customer_returns as $customer_return)
    <tr>
        <td class="label">&nbsp;&nbsp;{{{$item_number_return++}}}</td>
        <td class="label">&nbsp;&nbsp;{{{number_format($customer_return->qty) }}}</td>
        <td class="label">&nbsp;&nbsp;pcs</td>
        <td class="label">&nbsp;&nbsp;{{{$cc->date_return}}}</td>
        <td class="label">&nbsp;&nbsp;{{{$cc->plate_number}}}</td>
        <td class="label">&nbsp;&nbsp;{{{$cc->reference_number}}}</td>
        <td class="label">&nbsp;&nbsp;{{{$cc->ret_desc}}}</td>
    </tr>
    @endforeach
</table>

Output:输出: 在此处输入图片说明

You can use the <thead> tag to add a table header.您可以使用<thead>标记添加表头。 The header will then be applied to the top of each new page, allowing for a solid top border.然后将页眉应用到每个新页面的顶部,允许有一个实心的顶部边框。

Also, your company/item summary information should probably be defined outside the table, not randomly stuck inside a <tr> tag.此外,您的公司/项目摘要信息可能应该在表格之外定义,而不是随意卡在<tr>标签内。

<div>
    <!-- Company/item summary info should probably go out here -->
</div>
<table class="table-print">
    <thead>
        <!-- 
        This is really where your header row should go, using "th" instead of "td"...

        <tr>
            <th class="label-bold">Item</th>
            <th class="label-bold">Quantity</th>
            <th class="label-bold">Unit</th>
            <th class="label-bold">Date of Return</th>
            <th class="label-bold">Plate#</td>
            <th class="label-bold">Reference no.</th>
            <th class="label-bold">Remarks</th>
        </tr>
        
        ...but leaving it empty can still allow you a solid top border across pages.
        -->
    </thead>
    <tbody>
        <!-- Your existing data rows -->
    </tbody>
</table>

Just make sure all borders are defined as desired in the CSS.只需确保在 CSS 中根据需要定义所有边框。 You didn't include them above, so we don't know what you've done.你没有把它们包括在上面,所以我们不知道你做了什么。

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

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