Создайте собственную полосу прокрутки для div - PullRequest
0 голосов
/ 25 мая 2020

Я создал всплывающее окно, используя фиксированный div и размывая фон.

.blur#blur.active {
  filter: blur(20px);
  pointer-events: none;
  user-select: none;
}

.popup {
  position: fixed;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 600px;
  padding: 50px;
  box-shadow: 0 5px 30px rgba(0, 0, 0, .30);
  background: #fff;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  visibility: hidden;
  opacity: 0;
  transition: 0.5s;
}

.popup.active {
  top: 50%;
  visibility: visible;
  opacity: 1;
  transition: 0.5s;
}
<div id="textPopup" class="popup">
  <a onclick="hideAllForms()" style="cursor: pointer;"><img style="width: 35px; float: right;" src="images/icons/kreuz.png" /></a>
  <h2>Header for the text</h2>
  <p>Long text</p>
</div>

А это HTML

Теперь одно из этих всплывающих окон должно содержать длинный текст, поэтому вы должны иметь возможность прокручивать текст вниз в контейнере div и не прокручивать страницу вниз.

Спасибо!

Ответы [ 4 ]

0 голосов
/ 25 мая 2020

Добавьте фиксированный height и используйте overflow: auto;, чтобы включить прокрутку, когда содержимое превышает высоту контейнера.

.popup {
    position: fixed;
    width: 600px;
    height: 200px;
    background: #e0e0e0;
    overflow: auto;
}
<div id="textPopup" class="popup">
        <h2>Header for the text</h2>
        <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
0 голосов
/ 25 мая 2020

Мы можем попробовать использовать свойство переполнения в CSS. Но работает только для фиксированной высоты и ширины.

.popup{
    overflow: scroll;       //newly added
    position: fixed;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 600px;
    padding: 50px;
    box-shadow: 0 5px 30px rgba(0, 0, 0, .30);
    background: #fff;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    visibility: hidden;
    opacity: 0;
    transition: 0.5s;
}
0 голосов
/ 25 мая 2020

Ладно, у меня есть ответ. Это было просто

overflow-y: scroll;
max-height: 100%;
0 голосов
/ 25 мая 2020

В CSS добавьте overflow: scroll; или overflow: auto; в div с длинным текстом, и он должен прокрутиться.

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