仅当媒体屏幕是时才将宽度更改为 ***px

Change width to ***px only when media screen is

我想更改 table 的宽度,但它到处都在变化。我想在全屏时将宽度设置为 1000px。但它到处都是 1000px。因此,当我裁剪页面时,table 不再响应。

示例: Codepen http://codepen.io/anon/pen/OPjMyQ

/* 
Generic Styling, for Desktops/Laptops 
*/

.responsivetable {
  width: 100%;
  border-collapse: collapse;
}
/* Zebra striping */

.responsivetable tr:nth-of-type(odd) {
  background: #eee;
}
.responsivetable th {
  background: #333;
  color: white;
  font-weight: bold;
}
.responsivetable td,
.responsivetable th {
  padding: 6px;
  border: 1px solid #ccc;
  text-align: left;
}
@media only screen and (max-width: 760px),
(min-device-width: 768px) and (max-device-width: 1024px) {
  /* Force table to not be like tables anymore */
  .responsivetable,
  .responsivetable thead,
  .responsivetable tbody,
  .responsivetable th,
  .responsivetable td,
  .responsivetable tr {
    display: block;
  }
  /* Hide table headers (but not display: none;, for accessibility) */
  .responsivetable thead tr {
    position: absolute;
    top: -9999px;
    left: -9999px;
  }
  .responsivetable tr {
    border: 1px solid #ccc;
  }
  .responsivetable td {
    /* Behave  like a "row" */
    border: none;
    border-bottom: 1px solid #eee;
    position: relative;
    padding-left: 50%;
  }
  .responsivetable td:before {
    /* Now like a table header */
    position: absolute;
    /* Top/left values mimic padding */
    top: 6px;
    left: 6px;
    width: 45%;
    padding-right: 10px;
    white-space: nowrap;
  }
  /*
 Label the data
 */
  .responsivetable td:nth-of-type(1):before {
    content: "Dag";
  }
  .responsivetable td:nth-of-type(2):before {
    content: "Tijd";
  }
  .responsivetable td:nth-of-type(3):before {
    content: "Vak";
  }
  .responsivetable td:nth-of-type(4):before {
    content: "Klas";
  }
  .responsivetable td:nth-of-type(5):before {
    content: "Lokaal";
  }
  .responsivetable td:nth-of-type(6):before {
    content: "Leraar";
  }
}
<table class="responsivetable">
  <thead>
    <tr>
      <th>Dag</th>
      <th>Tijd</th>
      <th>Vak</th>
      <th>Klas</th>
      <th>Lokaal</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Maandag</td>
      <td>08:45 - 09:35</td>
      <td>Vergadering</td>
      <td>IC.11AO.a</td>
      <td>158</td>
    </tr>
    <tr>
      <td>Maandag</td>
      <td>08:45 - 09:35</td>
      <td>Vergadering</td>
      <td>IC.11AO.a</td>
      <td>158</td>
    </tr>
    <tr>
      <td>Maandag</td>
      <td>08:45 - 09:35</td>
      <td>Vergadering</td>
      <td>IC.11AO.a</td>
      <td>158</td>
    </tr>
    <tr>
      <td>Maandag</td>
      <td>08:45 - 09:35</td>
      <td>Vergadering</td>
      <td>IC.11AO.a</td>
      <td>158</td>
    </tr>
    <tr>
      <td>Maandag</td>
      <td>08:45 - 09:35</td>
      <td>Vergadering</td>
      <td>IC.11AO.a</td>
      <td>158</td>
    </tr>
    <tr>
      <td>Maandag</td>
      <td>08:45 - 09:35</td>
      <td>Vergadering</td>
      <td>IC.11AO.a</td>
      <td>158</td>
    </tr>

  </tbody>
</table>

你的问题不清楚。到处都是1000px?

简单的解决方案是,将其包装在 div 中并将 div 设置为 max-width:1000px;

<div class="responsive">
<table class="responsivetable">
...
</table>
</div>

.responsive{max-width:1000px;}
.responsivetable{width:100%;}

这将确保当页面全屏显示时,最外面的 div 将是您想要的 1000px,并且 table 将始终是周围 div 的 100% ].因此,由于任何元素上都没有固定宽度,因此它们将根据屏幕尺寸进行响应。

-Epik