CSS фиксированное положение столбцов таблицы на экране другого размера - PullRequest
0 голосов
/ 22 марта 2020

Я создаю адаптивный сайт.

У меня есть таблица с фиксированным первым столбцом. Но при изменении размера окна или представления на устройстве с другой шириной, превышающей 454 пикселя, фиксированный первый столбец смещается, а тело таблицы также удаляется.

Как создать адаптивную таблицу с фиксированный столбец, который не go неуместен с другой шириной устройства?

таблица выглядит нормально на этой ширине экрана , этот снимок экрана: при увеличении ширины фиксированного столбца ходы места

.pagewrap1 {
  width: 90%;
  background-color: orange;
  margin: 0 auto;
  padding: 0 20px 0 20px;
}

div.data {
  background-color: green;
}


/*.scroll {
	overflow-x: scroll;
}*/

table.data {
  border-width: 0px;
  width: 750px;
  background-color: yellow;
}

.auto-style2 {
  border-style: solid;
  border-width: 1px;
}

.auto-style2b {
  border-style: solid;
  border-width: 1px;
  background-color: purple;
}

@media only screen and (max-width: 740px) {
  .pagewrap {
    background-color: blue;
  }
  .scroll {
    overflow-x: scroll;
    margin-left: 30px;
  }
  .auto-style2b {
    position: absolute;
    left: 30px;
    width: 25px;
  }
  table.data {
    width: 100%;
  }
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta content="en-gb" http-equiv="Content-Language" />
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
  <title>Untitled 1</title>
</head>
<body>
  <div class="pagewrap1">
    <div class="data">
      <div class="scroll">
        <table class="data">
          <tr>
            <th class="auto-style2b">&nbsp;</th>
            <th style="width: 195px" class="auto-style2">column a</th>
            <th style="width: 195px" class="auto-style2">column b</th>
            <th style="width: 195px" class="auto-style2">column c</th>
          </tr>
          <tr>
            <th style="height: 120px;" class="auto-style2b">c1</th>
            <td style="height: 120px; width: 195px;" class="auto-style2">
              123456789123456<br />
            </td>
            <td style="height: 120px; width: 195px;" class="auto-style2">
              123456789123456789</td>
            <td style="height: 120px; width: 195px;" class="auto-style2">
              123456789123456789123456</td>
          </tr>
          <tr>
            <th class="auto-style2b">c2</th>
            <td style="width: 195px" class="auto-style2">5855</td>
            <td style="width: 195px" class="auto-style2">&nbsp;</td>
            <td style="width: 195px" class="auto-style2">&nbsp;</td>
          </tr>
          <tr>
            <th class="auto-style2b">c3</th>
            <td style="width: 195px" class="auto-style2">&nbsp;</td>
            <td style="width: 195px" class="auto-style2">&nbsp;</td>
            <td style="width: 195px" class="auto-style2">&nbsp;</td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</body>
</html>

1 Ответ

0 голосов
/ 22 марта 2020

Кажется, проблема связана с этим правилом position: absolute:

.auto-style2b {
   position: absolute; /* it causes the gap */
   left: 30px;
   width:25px;
}

Устранение проблемы устраняет проблему разрыва.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...