CSS中的表分页符

时间:2015-10-26 09:55:26

标签: php html css printing

我正在用HTML实现页面打印。 我的目标是如果一张桌子不在同一页面中,整个表格将被转移到下一页。我该怎么做呢。我有这个代码..请帮助我。

这是我的CSS部分。

    <style type="text/css">
    .printOnly {
        margin-top: 100px;
        display: none;
    }    
   .textSummaryTable { page-break-inside:auto }
   .textSummaryTable tr { page-break-inside:avoid; page-break-after:auto }

    @media print {
        .summaryTable tr:nth-child(odd){ background-color:#E1E4E5;}
        .summaryTable tr:nth-child(even)    { background-color:#ffffff; }

      .printOnly { display: block; }
        .panel {
            border: 1px solid transparent;
            padding: 2px;
            margin: 0;
        }

        .textSummaryTable{ border:1px solid gray; }
        .textSummaryTable td{ border:1px solid gray; }

        #main {
            overflow: hidden;
            position: absolute;
            padding: 0px;
            height: auto;
            width: 100%;
        }
        #title { display: none; }
        #line-break { display: block; }
        .textSummaryTable { width: 100%; }
    }

    @media screen {
        #line-break { display: none; }
    }
</style>

我的桌子在这里。

<?php
$this->pageTitle = Yii::app()->name . ' - View Evaluation';  
$user = LoginForm::getUser();
?>    
  <?php $participants = $modelE->evaluationDetails; ?>

        <style type="text/css">
            @media print {
                body {
                    overflow: hidden;
                }
            }
        </style>

        <div class=" non-printable">
            <div class='pull-right non-printable'>
                    <button id="btnPrint" type="button" class="btn btn-default pull-right"  onclick="window.print();">
                        <span class="glyphicon glyphicon-print"></span>&nbsp; Print
                    </button>
            </div>
            <?php
        $startDate = date("M j, Y", strtotime($modelE->start_date));
        $endDate = date("M j, Y", strtotime($modelE->end_date));
    ?>
        </div>
        <div id='line-break'>
            <br>
            <br>
            <br>
        </div>
        <div class="container-fluid">
            <div class="printable">
                <h4><?php echo htmlentities($modelE->evaluationForm->name); ?></h4>
                <h5><?php echo $startDate; ?> - <?php echo $endDate; ?></h5>
                <h5>Candidate:  <?php echo htmlentities($modelE->evaluatee); ?></h5>
                <h5>Overall Evaluation:  <?php echo htmlentities($modelE->getResult()); ?></h5>
                <h5>Participants:  <?php echo htmlentities(count($participants)); ?></h5>
                <div class="panel panel-default">
                    <div class="panel-body">
                        <h5><strong>Instructions: </strong> <?php echo htmlentities($modelE->evaluationForm->description); ?></h5>
                        <!--  <h4>Results Summary</h4>  -->
                        <?php

            $radioFlag = false;
            foreach ($modelE->evaluationForm->evaluationFormDetails as $question) {
                    $criteria = new CDbCriteria;
                    $criteria->with = 'evalResult';
                    $criteria->addInCondition('eval_form_question_id', array($question->id));
                    $criteria->addInCondition('evalResult.eval_id', array($modelE->id));
                    $resultSet = EvaluationResultsDetails::model()->findAll($criteria);

                if ( strtolower($question->field_type) != "radioheader" && $question->field_type != "slider"  ) {
                    if($radioFlag){
                        echo "</table>";
                        $radioFlag = false;
                    }
                    if( $question->field_type == "text" ) {
                        echo "<h4>" . $question->field_name . "</h4>";
                    }
                    else {
                        echo "<table class='textSummaryTable'><tr><td style='width: 100%'><label>" . $question->field_name . "</label></td></tr>";
                        foreach ($resultSet as $answer) {
                            echo "<tr><td>" . $answer->eval_answer . "</td></tr>";
                        }
                        echo "</table>";
                    }
                } else {
                    if(!$radioFlag){
                        echo '<table border-size = 0px width=100% class="summaryTable">';
                        $radioFlag = true;
                    }
                    echo "<tr><td style='width: 90%'>" . $question->field_name . "";
                    echo "</td><td style='width: 10%'>";
                    $sum = 0;
                    $count = 0;
                    foreach ($resultSet as $answer) {
                        $count++;
                        $sum += $answer->eval_answer;
                    }
                    echo $count == 0 ? "-" : number_format($sum / $count, 2);

                    echo "</td></tr>";
                    /*** end here ***/
                }

            }
            if($radioFlag){
                echo "</table>";
            }
        ?>
                            <table class="printOnly">
                                <tr>
                                    <td colspan="2">
                                        <p> I hereby certify that all information declared in this document are accurate and true. Each item have been discussed with my Immediate Superior and mutually agreed upon.</p>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <p>Prepared by
                                            <?= $modelE->project->manager->family_name . ", " . $modelE->project->manager->first_name ?>
                                        </p>
                                        Date <?= date("Y-m-d"); ?>

                                    </td>
                                    <td>
                                        <p>Conformed by <?= $modelE->evaluatee ?></p>
                                        Date
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <p>Noted by HR Division</p>
                                    </td>
                                </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        </div>

0 个答案:

没有答案