HTML / CSS - Позиция Sticky и преобразование без изменения размера области просмотра - PullRequest
0 голосов
/ 28 октября 2018

На моем сайте есть элементы, использующие преобразования.Я заметил, что эти преобразования изменяют размер области просмотра.Обычно я решаю эту проблему, предоставляя html и body overflow-x: hidden, но тогда мой заголовок с position: sticky не работает.

Как я могу предотвратить преобразование преобразованных элементов в размер области просмотра и продолжать использовать position: sticky?

Я добавил пример ниже.

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.scale {
  padding: 100px;
  width: 100%;
  height: 400px;
  background-color: green;
  transform: scale(2);
  position: relative;
  z-index 1;
}

header {
  position: sticky;
  position: -webkit-sticky;
  top: 0;
  left 0;
  right 0;
  height: 50px;
  background-color: red;
  z-index: 2;
}
<header>I want this header to remain sticky</header>
<div class="scale">
But I don't want this div to resize the x-axis of the viewport.
</div>

1 Ответ

0 голосов
/ 28 октября 2018

Используйте другой контейнер, где вы можете применить overflow:hidden

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.scale {
  padding: 100px;
  width: 100%;
  height: 400px;
  background-color: green;
  transform: scale(2);
  position: relative;
  z-index 1;
}

.container {
  overflow: hidden;
}

header {
  position: sticky;
  position: -webkit-sticky;
  top: 0;
  left 0;
  right 0;
  height: 50px;
  background-color: red;
  z-index: 2;
}
<header>I want this header to remain sticky</header>
<div class="container">
  <div class="scale">
    But I don't want this div to resize the x-axis of the viewport.
  </div>
</div>
...