Ключ находится в настройке height
и width
ваших родительских и дочерних элементов.
Горизонтальная прокрутка (ось X) может быть достигнута, если общая ширина дочерних элементов больше, чем ширина родительского элемента плюс использование overflow: auto
для родительского элемента.
Вертикальная прокрутка (ось Y) может быть достигнута, если общая высота дочерних элементов больше высоты родительского элемента плюс использование overflow: auto
для родительского элемента.
Вот рабочий код: https://codesandbox.io/s/kind-gates-djhnx?file=/src/styles.css
html файл:
<div id="parent">
<div id="child-1">
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.
</div>
<div id="child-2">
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.
</div>
<div id="child-3">
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.
</div>
</div>
CSS-файл:
#parent {
overflow: auto;
height: 300px;
width: 300px;
background-color: gainsboro;
}
#child-1 {
overflow: auto;
width: 500px;
background-color: lightblue;
}
#child-2 {
overflow: auto;
width: 500px;
background-color: lightgreen;
}
#child-3 {
overflow: auto;
width: 500px;
background-color: lightcoral;
}
overflow-y
или простоoverflow: auto
@Dai Вы имеете в виду
overflow-y
илиoverflow:auto
в родительском элементе? На моем не работает@MinseoLee использует
overflow: auto
для родителяdiv
.@Blaze_droid Не работает так же, извините
Ваш родитель должен иметь свойство переполнения, плюс вам нужна некоторая высота для его работы. Если высота меньше роста ваших детей вместе взятых, вы получите свиток
@MinseoLee, вы можете попробовать
overflow:scroll !important;
, чтобы переопределить какой-то уже существующий стиль.Я добавил рабочий код ответа. пожалуйста, чек.