无法应用分页

时间:2016-07-19 12:57:26

标签: html css printing page-break

我有一个月份列表,我想在打印时每页显示一个,所以我想使用分页符,但问题是我无法应用分页符。我也试过放<div class="pagebreak"></div>,但我不明白为什么它没有生效。这是我的代码:

.pagebreak{
  page-break-after: always;
  }
<table class="fc-year-main-table fc-border-separate">
    <tr>
        <td class="fc-year-month-border fc-first"></td>
        <td class="fc-year-monthly-td" style="">
            <div class="fc-year-monthly-name fc-first"><a name="201401" data-year="2014" data-month="0" href="#">January</a></div>
            <div class="fc-row fc-widget-header">
                <table class="fc-year-month-header">
                    <thead>
                        <tr class="fc-year-week-days"></tr>
                        <tr></tr>
                    </thead>
                </table>
            </div>
            <div class="fc-day-grid-container">
                <div class="fc-day-grid"></div>
            </div>
            <div class="fc-year-monthly-footer"></div>
        </td>
        <td class="fc-year-month-border fc-last"></td>

    <tr class="pagebreak">
        <td class="fc-year-month-border fc-first"></td>
        <td class="fc-year-monthly-td" style="">
            <div class="fc-year-monthly-name"><a name="201402" data-year="2014" data-month="1" href="#">February</a></div>
            <div class="fc-row fc-widget-header">
                <table class="fc-year-month-header">
                    <thead>
                        <tr class="fc-year-week-days"></tr>
                        <tr></tr>
                    </thead>
                </table>
            </div>
            <div class="fc-day-grid-container">
                <div class="fc-day-grid"></div>
            </div>
            <div class="fc-year-monthly-footer"></div>
        </td>
        <td class="fc-year-month-border fc-last"></td>
    </tr>

    <tr class="pagebreak">
        <td class="fc-year-month-border fc-first"></td>
        <td class="fc-year-monthly-td" style="">
            <div class="fc-year-monthly-name"><a name="201403" data-year="2014" data-month="2" href="#">March</a></div>
            <div class="fc-row fc-widget-header">
                <table class="fc-year-month-header">
                    <thead>
                        <tr class="fc-year-week-days"></tr>
                        <tr></tr>
                    </thead>
                </table>
            </div>
            <div class="fc-day-grid-container">
                <div class="fc-day-grid"></div>
            </div>
            <div class="fc-year-monthly-footer"></div>
        </td>
        <td class="fc-year-month-border fc-last"></td>
    </tr>

    <tr class="pagebreak">
        <td class="fc-year-month-border fc-first"></td>
        <td class="fc-year-monthly-td" style="">
            <div class="fc-year-monthly-name"><a name="201404" data-year="2014" data-month="3" href="#">April</a></div>
            <div class="fc-row fc-widget-header">
                <table class="fc-year-month-header">
                    <thead>
                        <tr class="fc-year-week-days"></tr>
                        <tr></tr>
                    </thead>
                </table>
            </div>
            <div class="fc-day-grid-container">
                <div class="fc-day-grid"></div>
            </div>
            <div class="fc-year-monthly-footer"></div>
        </td>
        <td class="fc-year-month-border fc-last"></td>
    </tr>

</table>

1 个答案:

答案 0 :(得分:0)

第一个<tr>没有pagebreak类,其</tr>缺失,除了那些问题(修复它们)之外,它使用

@media print {
    tr.pagebreak  { display: block; page-break-before: always; }
}  

pagebreak中的tr似乎有点棘手,请查看此问题Applying "page-break-before" to a table row (tr)

工作演示:

window.print();
        @media print {
            tr.pagebreak  { display: block; page-break-before: always; }
        }   
<table class="fc-year-main-table fc-border-separate">
    <tr class="pagebreak">
        <td class="fc-year-month-border fc-first"></td>
        <td class="fc-year-monthly-td" style="">
            <div class="fc-year-monthly-name fc-first"><a name="201401" data-year="2014" data-month="0" href="#">January</a></div>
            <div class="fc-row fc-widget-header">
                <table class="fc-year-month-header">
                    <thead>
                        <tr class="fc-year-week-days"></tr>
                        <tr></tr>
                    </thead>
                </table>
            </div>
            <div class="fc-day-grid-container">
                <div class="fc-day-grid"></div>
            </div>
            <div class="fc-year-monthly-footer"></div>
        </td>
        <td class="fc-year-month-border fc-last"></td>
	</tr>
    <tr class="pagebreak">
        <td class="fc-year-month-border fc-first"></td>
        <td class="fc-year-monthly-td" style="">
            <div class="fc-year-monthly-name"><a name="201402" data-year="2014" data-month="1" href="#">February</a></div>
            <div class="fc-row fc-widget-header">
                <table class="fc-year-month-header">
                    <thead>
                        <tr class="fc-year-week-days"></tr>
                        <tr></tr>
                    </thead>
                </table>
            </div>
            <div class="fc-day-grid-container">
                <div class="fc-day-grid"></div>
            </div>
            <div class="fc-year-monthly-footer"></div>
        </td>
        <td class="fc-year-month-border fc-last"></td>
    </tr>

    <tr class="pagebreak">
        <td class="fc-year-month-border fc-first"></td>
        <td class="fc-year-monthly-td" style="">
            <div class="fc-year-monthly-name"><a name="201403" data-year="2014" data-month="2" href="#">March</a></div>
            <div class="fc-row fc-widget-header">
                <table class="fc-year-month-header">
                    <thead>
                        <tr class="fc-year-week-days"></tr>
                        <tr></tr>
                    </thead>
                </table>
            </div>
            <div class="fc-day-grid-container">
                <div class="fc-day-grid"></div>
            </div>
            <div class="fc-year-monthly-footer"></div>
        </td>
        <td class="fc-year-month-border fc-last"></td>
    </tr>

    <tr class="pagebreak">
        <td class="fc-year-month-border fc-first"></td>
        <td class="fc-year-monthly-td" style="">
            <div class="fc-year-monthly-name"><a name="201404" data-year="2014" data-month="3" href="#">April</a></div>
            <div class="fc-row fc-widget-header">
                <table class="fc-year-month-header">
                    <thead>
                        <tr class="fc-year-week-days"></tr>
                        <tr></tr>
                    </thead>
                </table>
            </div>
            <div class="fc-day-grid-container">
                <div class="fc-day-grid"></div>
            </div>
            <div class="fc-year-monthly-footer"></div>
        </td>
        <td class="fc-year-month-border fc-last"></td>
    </tr>

</table>