【问题标题】:CSS styles from style tag not properly being applied to page样式标签中的 CSS 样式未正确应用于页面
【发布时间】:2019-11-06 21:55:09
【问题描述】:

尝试从 html 页面生成带有 jsPDF 的 pdf,我成功了,但由于某种原因,我的样式没有应用于 Firefox,我开始查看正在生成的 html,当我打开时看到了本地的 HTML 由于某种原因没有应用样式,这应该很简单所有样式都在样式标签中,我没有导入文件但还不行。这是 HTML:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>FF Testing</title>
    <style>
      html {
        box-sizing: border-box !important;
      }

      .page_added {
        border: 0 none !important;
      }
      .body_sub {
        font-size: 1rem !important;
        font-family: Aria, sans-serif;
        font-size: 1rem;
        font-weight: 400;
        line-height: 1.5;
        color: #212529;
        background-color: #fff !important;
        margin: 0 !important;
        padding: 1rem !important;
        box-sizing: border-box !important;
      }
      table {
        width: 100% !important;
        /*margin-bottom: 1rem;*/
        background-color: transparent !important;
        /*border-collapse: separate !important;*/
        /*border-spacing: 0 !important;*/
        padding: 0 !important;
        margin: 0 !important;
      }
      tr {
        padding-bottom: 0;
        padding-top: 0;
        margin-bottom: 0;
        margin-top: 0;
        border-spacing: 0;
        border: 1px solid #dee2e6;
        background-color: transparent;
        /*border-collapse: collapse;*/
      }
      .title {
        border: 0 none !important;
      }
      .table td {
        padding: 8px;
        vertical-align: top;
      }
      .table td.or {
        font-weight: bold;
        color: blue;
        background: #dee2e6;
        text-align: center;
        font-size: 1.5rem;
      }
      .and {
        font-weight: bold;
        color: blue;
      }
      .table td.origin {
        font-weight: bold;
        color: black;
        text-align: center;
        font-size: 1.5rem;
        /*break-before: avoid;*/
      }
      .diseeaseTitle {
        font-weight: bold;
        font-size: 1.5rem;
        padding-bottom: 8px;
      }
    </style>
  </head>
  <body>
    <div class="body_sub">
      <table class="table">
        <tr class="title">
          <td colspan="3">
            <h2>NBA5387430702 <br /></h2>
          </td>
        </tr>
        <tr class="title">
          <td colspan="3">
            <small
              >Subtitle here Subtitle here Subtitle here Subtitle here Subtitle here Subtitle here Subtitle here</small
            >
          </td>
        </tr>
        <tr class="title">
          <td colspan="3">
            <h3 class="diseeaseTitle">
              <strong>TITLE TITLE TITLE TITLE TITLE </strong>
            </h3>
          </td>
        </tr>
        <tr>
          <td colspan="3" class="origin"> Smaller title Smaller title Smaller title</td>
        </tr>
        <tr>
          <td colspan="1" style="width: 40%;">question number one?</td>
          <td colspan="1">
            Year
          </td>
          <td colspan="1"></td>
        </tr>
        <tr>
          <td colspan="1" style="width: 40%;">
            questions number two which is slightly longer not as short as question one?
          </td>
          <td colspan="1">
            Single Choice
          </td>
          <td colspan="1">
            <span>
              Some answer option; </span
            ><span>
              No; </span
            ><span>
              Not sure; </span
            ><span>
              Another answer option (AAO);
            </span>
          </td>
        </tr>
        <tr>
          <td colspan="1" style="width: 40%;">
            This is also a question since this is a questionnaire so I need many questions, ok?
          </td>
          <td colspan="1">
            Single Choice
          </td>
          <td colspan="1">
            <span>
              Below 30 percent; </span
            ><span>
              30-39 percent; </span
            ><span>
              40-49 percent; </span
            ><span>
              50-59 percent; </span
            ><span>
              60-69 percent; </span
            ><span>
              70-90 percent; </span
            ><span>
              80 percent of greater; </span
            ><span>
              Not sure; </span
            ><span>
              Last Option
            </span>
          </td>
        </tr>
        <tr>
          <td colspan="1" style="width: 40%;">
            Are you currently reading this questionnaire right now, crazy stuff huh?
          </td>
          <td colspan="1">
            Multiple Choice
          </td>
          <td colspan="1">
            <span>
              Answer 3534; </span
            ><span>
              Some other answer; </span
            ><span>
              Bla bLa bal; </span
            ><span>
              Zebras giraffes and thingamiaggers; </span
            ><span>
              ghslhgslikh; </span
            ><span>
              skljgslkn; </span
            ><span>
              xngbxklbgl; </span
            ><span>
              svgmsmn; </span
            ><span>
              hsxshfshsd; </span
            ><span>
              xhdxhsdh; </span
            ><span>
              Not sure; </span
            ><span>
              Not taking this anymore
            </span>
          </td>
        </tr>
        <tr>
          <td colspan="1" style="width: 40%;">
            Do you have any of the following something something ? Please select all that apply.
          </td>
          <td colspan="1">
            Multiple Choice
          </td>
          <td colspan="1">
            <span>
              this that or possibly those things; </span
            ><span>
              Active boromoter (chronic or acute); </span
            ><span>
              Active craziness requires treatment; </span
            ><span>
              Chronic eating of burgers; </span
            ><span>
              Serious addicition to football; </span
            ><span>
              No significant conditions
            </span>
          </td>
        </tr>
      </table>

      <!---->
      <table class="table">
        <!---->
      </table>
      <p style="break-before: page;">
        &nbsp;
      </p>
      <table class="table">
        <tr>
          <td colspan="3" class="origin">
            Match Criteria for this questionnaire
          </td>
        </tr>
        <tr>
          <td style="width: 40%;">What year were you born?</td>
          <td>is greater than (years)</td>
          <td></td>
          <td><!----></td>
        </tr>
        <!---->
      </table>

      <p style="break-before: page;">&nbsp;</p>
    </div>
  </body>
</html>

看起来很糟糕的一些问题是tr 元素中的边框没有显示,但更普遍的是,似乎至少大多数样式都没有被应用。我错过了什么我的样式没有被应用?

【问题讨论】:

    标签: html css


    【解决方案1】:

    将此添加到您的样式中,它应该可以工作

    table {
        border-collapse: collapse;
    }
    

    【讨论】:

      【解决方案2】:

      大多数样式不会应用于tr

      您必须将您的边框样式提供给td。要删除td 之间的空格,您必须将属性cellspacing=0cellpadding=0 添加到table。您可以为每个tds 和border-left 添加border-topborder-bottomfirst-childborder-rightlast-child

      希望你得到它

      【讨论】:

        【解决方案3】:
        1. 首先,没有名为 .or.and 的类,因此无法应用样式。

        2. 您在 tr 样式中拼错了 padding-bottom 属性。

        3. 要获得表格的边框,您需要在表格样式中添加 border-collapse:collapse; 属性。

        我对您的代码进行了一些更改,据我说一切正常,如果您想添加更多样式或需要在代码中进行更改,请告诉我。

        代码:-

        <!DOCTYPE html>
        <html lang="en">
          <head>
            <meta charset="UTF-8" />
            <title>FF Testing</title>
            <style>
              html {
                box-sizing: border-box !important;
              }
        
              .page_added {
                border: 0 none !important;
              }
              .body_sub {
                font-size: 1rem !important;
                font-family: Aria, sans-serif;
                font-size: 1rem;
                font-weight: 400;
                line-height: 1.5;
                color: #212529;
                background-color: #fff !important;
                margin: 0 !important;
                padding: 1rem !important;
                box-sizing: border-box !important;
              }
              table {
                width: 100% !important;
                /*margin-bottom: 1rem;*/
                background-color: transparent !important;
                /*border-collapse: separate !important;*/
                /*border-spacing: 0 !important;*/
                padding: 0 !important;
                margin: 0 !important;
                border-collapse:collapse; 
              }
              tr {
                padding-bottom: 0;
                padding-top: 0;
                margin-bottom: 0;
                margin-top: 0;
                border-spacing: 0;
                border: 1px solid #dee2e6;
                background-color: transparent;
                /*border-collapse: collapse;*/
              }
              
              .title {
                border: 0 none !important;
              }
               
              td {
                padding: 8px;
                vertical-align: top;
              }
              
               .origin {
                font-weight: bold;
                color: blue;
                background: #dee2e6;
                text-align: center;
                font-size: 1.5rem;
              }
              
              .origin {
                font-weight: bold;
                color: black;
                text-align: center;
                font-size: 1.5rem;
                /*break-before: avoid;*/
              }
              .diseeaseTitle {
                font-weight: bold;
                font-size: 1.5rem;
                padding-bottom: 8px;
              }
            </style>
          </head>
          <body>
            <div class="body_sub">
              <table class="table">
                <tr class="title">
                  <td colspan="3">
                    <h2>NBA5387430702 <br /></h2>
                  </td>
                </tr>
                <tr class="title">
                  <td colspan="3">
                    <small
                      >Subtitle here Subtitle here Subtitle here Subtitle here Subtitle here Subtitle here Subtitle here</small
                    >
                  </td>
                </tr>
                <tr class="title">
                  <td colspan="3">
                    <h3 class="diseeaseTitle">
                      <strong>TITLE TITLE TITLE TITLE TITLE </strong>
                    </h3>
                  </td>
                </tr>
                <tr>
                  <td colspan="3" class="origin"> Smaller title Smaller title Smaller title</td>
                </tr>
                <tr>
                  <td colspan="1" style="width: 40%;">question number one?</td>
                  <td colspan="1">
                    Year
                  </td>
                  <td colspan="1"></td>
                </tr>
                <tr>
                  <td colspan="1" style="width: 40%;">
                    questions number two which is slightly longer not as short as question one?
                  </td>
                  <td colspan="1">
                    Single Choice
                  </td>
                  <td colspan="1">
                    <span>
                      Some answer option; </span
                    ><span>
                      No; </span
                    ><span>
                      Not sure; </span
                    ><span>
                      Another answer option (AAO);
                    </span>
                  </td>
                </tr>
                <tr>
                  <td colspan="1" style="width: 40%;">
                    This is also a question since this is a questionnaire so I need many questions, ok?
                  </td>
                  <td colspan="1">
                    Single Choice
                  </td>
                  <td colspan="1">
                    <span>
                      Below 30 percent; </span
                    ><span>
                      30-39 percent; </span
                    ><span>
                      40-49 percent; </span
                    ><span>
                      50-59 percent; </span
                    ><span>
                      60-69 percent; </span
                    ><span>
                      70-90 percent; </span
                    ><span>
                      80 percent of greater; </span
                    ><span>
                      Not sure; </span
                    ><span>
                      Last Option
                    </span>
                  </td>
                </tr>
                <tr>
                  <td colspan="1" style="width: 40%;">
                    Are you currently reading this questionnaire right now, crazy stuff huh?
                  </td>
                  <td colspan="1">
                    Multiple Choice
                  </td>
                  <td colspan="1">
                    <span>
                      Answer 3534; </span
                    ><span>
                      Some other answer; </span
                    ><span>
                      Bla bLa bal; </span
                    ><span>
                      Zebras giraffes and thingamiaggers; </span
                    ><span>
                      ghslhgslikh; </span
                    ><span>
                      skljgslkn; </span
                    ><span>
                      xngbxklbgl; </span
                    ><span>
                      svgmsmn; </span
                    ><span>
                      hsxshfshsd; </span
                    ><span>
                      xhdxhsdh; </span
                    ><span>
                      Not sure; </span
                    ><span>
                      Not taking this anymore
                    </span>
                  </td>
                </tr>
                <tr>
                  <td colspan="1" style="width: 40%;">
                    Do you have any of the following something something ? Please select all that apply.
                  </td>
                  <td colspan="1">
                    Multiple Choice
                  </td>
                  <td colspan="1">
                    <span>
                      this that or possibly those things; </span
                    ><span>
                      Active boromoter (chronic or acute); </span
                    ><span>
                      Active craziness requires treatment; </span
                    ><span>
                      Chronic eating of burgers; </span
                    ><span>
                      Serious addicition to football; </span
                    ><span>
                      No significant conditions
                    </span>
                  </td>
                </tr>
              </table>
        
              <!---->
              <table class="table">
                <!---->
              </table>
              <p style="break-before: page;">
                &nbsp;
              </p>
              <table class="table">
                <tr>
                  <td colspan="3" class="origin">
                    Match Criteria for this questionnaire
                  </td>
                </tr>
                <tr>
                  <td style="width: 40%;">What year were you born?</td>
                  <td>is greater than (years)</td>
                  <td></td>
                  <td><!----></td>
                </tr>
                <!---->
              </table>
        
              <p style="break-before: page;">&nbsp;</p>
            </div>
          </body>
        </html>

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-08-29
          • 2012-05-09
          • 1970-01-01
          • 2022-08-17
          相关资源
          最近更新 更多