【问题标题】:header not being responsive when resizing调整大小时标题没有响应
【发布时间】:2018-11-28 15:08:11
【问题描述】:

我有一个表格,当我调整大小时,它不会在 Web 视图上显示我的标题 Steps,它确实显示得很好 - 但是当我调整大小时,我看不到我的 Steps 标题。有没有办法在下面的代码中使用 css 或 jstl/jsf 标签解决这个问题?谢谢您的帮助。像这样:https://imgur.com/a/cSRshbD

图像出现:

这是我的代码:

table {
    margin: auto;
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
}

th,
td {
    padding: 5px 10px;
}

tr {
    border-bottom: 1px solid #ccc;
}

thead th {
    border-bottom: 2px solid #ddd;
}

/* You will need to display:none the duplicated header in responsible-table-item*/

tr.responsive-table-item .responsive-table-cell {
    display: none;
}

/* Add screen proportion or class when break occurs */
@media (max-width: 768px) {
    /* Hide table headers */
    .table-header {
        display: none;
    }

    tr.responsive-table-item {
        display: block;
    }

    tr.responsive-table-item .responsive-table-cell {
        display: inline-block;
    }

    tr.responsive-table-item td:first-child {
        background-color: #ccc;
        display: block;
        text-align: center;
        width: 100%;
    }

    tr.responsive-table-item td,
    tr.responsive-table-item th {
        display: inline-block;
        width: calc(50% - 22px);
        /* Cell Border + padding*/
        word-break: break-all;
        vertical-align: top;
    }
}
<table class="responsive-table">
    <thead>
        <tr class="table-header"> 
            <th></th>

            <c:forEach var="stepNumber" begin="1" end="#{testBean.jobEntity.stepSize}" varStatus="loop">
                <c:if test="${loop.index lt 9}"> 
                    <th  class="responsive-table-cell">Step #{stepNumber}</th>
                </c:if>
            </c:forEach>
        </tr>


        <c:forEach items="#{testBean.jobEntity.jobRows}" var="jobRow"> 
            <tr class="responsive-table-item">
                <td class="left-header">#{jobRow.rateType}</td>

                <c:forEach items="#{jobRow.steps}" var="step" varStatus="loop">
                    <c:if test="${loop.index lt 8}"> 
                    <th class="left-header">#{step.amount}</th>
                    </c:if>
                </c:forEach>

            </tr>
        </c:forEach>
    </thead>
</table> 

【问题讨论】:

  • 所以如果你创建一个没有jstl的静态表(实际上这与jsf无关)它可以工作吗?
  • 但是,它使用静态表格。如果您愿意,我可以向您展示静态方式 - 但是,我想使用上面的代码。
  • 然后看看 client-sIde html 中静态创建的表和基于 jstl 的表之间的差异。不应该太难,也很可能与 jstl 无关。并在问题中发布所有相关信息

标签: html css jstl responsive


【解决方案1】:

这是我的回答:

table {
  margin: auto;
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
}

th,
td {
  padding: 5px 10px;
}

tr {
  border-bottom: 1px solid #ccc;
}

thead th {
  border-bottom: 2px solid #ddd;
}



tr.responsive-table-item .responsive-table-cell {
  display: none;
}

   
@media (max-width: 768px) {
  
  .table-header {
    display: none;
  }

  tr.responsive-table-item {
    display: block;
  }

  tr.responsive-table-item .responsive-table-cell {
    display: inline-block;
  }

  tr.responsive-table-item td:first-child {
    background-color: #ccc;
    display: block;
    text-align: center;
    width: 100%;
  }

  tr.responsive-table-item td,
  tr.responsive-table-item th {
    display: inline-block;
    width: calc(50% - 22px);
   
    word-break: break-all;
    vertical-align: top;
  }
}
<table class="responsive-table">
  <thead>
    <tr class="table-header">
      <th></th>
      <th class="right-header">Step 1</th>
      <th class="right-header">Step 2</th>
      <th class="right-header">Step 3</th>
      <th class="right-header">Step 4</th>
      <th class="right-header">Step 5</th>
      <th class="right-header">Step 6</th>
      <th class="right-header">Step 7</th>
      <th class="right-header">Step 8</th>
    </tr>
  </thead>
  <tbody>
    
    <tr class="responsive-table-item">
      <td class="left-header">Test</td>
      <th class="responsive-table-cell">Step 1</th>
      <td class="left-header"> $57.36</td>
      <th class="responsive-table-cell">Step 2</th>
      <td class="left-header"> $58.94</td>
      <th class="responsive-table-cell">Step 3</th>
      <td class="left-header"> $60.56</td>
      <th class="responsive-table-cell">Step 4</th>
      <td class="left-header"> $62.23</td>
      <th class="responsive-table-cell">Step 5</th>
      <td class="left-header"> $65.70</td>
      <th class="responsive-table-cell">Step 6</th>
      <td class="left-header"> $69.37</td>
      <th class="responsive-table-cell">Step 7</th>
      <td class="left-header"> $73.23</td>
      <th class="responsive-table-cell">Step 8</th>
      <td class="left-header"> $77.31</td>
    </tr>
    <tr class="responsive-table-item">
      <td class="left-header">Test</td>
      <th class="responsive-table-cell">Step 1</th>
      <td class="left-header"> $4,588.80</td>
      <th class="responsive-table-cell">Step 2</th>
      <td class="left-header"> $4,715.20</td>
      <th class="responsive-table-cell">Step 3</th>
      <td class="left-header"> $4,844.80</td>
      <th class="responsive-table-cell">Step 4</th>
      <td class="left-header"> $4,978.40</td>
      <th class="responsive-table-cell">Step 5</th>
      <td class="left-header"> $5,256.00</td>
      <th class="responsive-table-cell">Step 6</th>
      <td class="left-header"> $5,549.60</td>
      <th class="responsive-table-cell">Step 7</th>
      <td class="left-header"> $5,858.40</td>
      <th class="responsive-table-cell">Step 8</th>
      <td class="left-header"> $6,184.80</td>
    </tr>
    <tr class="responsive-table-item">
      <td class="left-header">Test</td>
      <th class="responsive-table-cell">Step 1</th>
      <td class="left-header"> $119,767.68</td>
      <th class="responsive-table-cell">Step 2</th>
      <td class="left-header"> $123,066.72</td>
      <th class="responsive-table-cell">Step 3</th>
      <td class="left-header"> $126,449.28</td>
      <th class="responsive-table-cell">Step 4</th>
      <td class="left-header"> $129,936.24</td>
      <th class="responsive-table-cell">Step 5</th>
      <td class="left-header"> $137,181.60</td>
      <th class="responsive-table-cell">Step 6</th>
      <td class="left-header"> $144,844.56</td>
      <th class="responsive-table-cell">Step 7</th>
      <td class="left-header"> $152,904.24</td>
      <th class="responsive-table-cell">Step 8</th>
      <td class="left-header"> $161,423.28</td>
    </tr>
  </tbody>
</table>

【讨论】:

    【解决方案2】:

    在左标题类中尝试width: 13%

    left-header{
    width: 13%;
    font-weight:normal;
    color:#039;
    border-right:2px solid #6678b1;
    padding:10px 8px;
    text-align:left;
    } 
    

    【讨论】:

    • 显示正常,但在移动视图中缺少步骤。
    • 等等。现在我进行了硬刷新,我的桌子看起来更大了,像这样:imgur.com/a/2EEGP7X
    • 我认为最好的是media-queries,不是吗?
    • css 可以工作,但在桌面视图上没有显示数字,在移动视图上也没有正确显示步骤。
    【解决方案3】:

    当表格开始看起来很糟糕时,尝试媒体查询,例如:

    @media all and (max-width: XXXpx){
    here you need to put new css styles for example ( smaller font or sthg)
    }
    

    【讨论】:

      猜你喜欢
      • 2013-08-24
      • 1970-01-01
      • 2013-02-18
      • 2011-02-04
      • 1970-01-01
      • 1970-01-01
      • 2018-02-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多