I want to display the seats in the cinema hall. Sometimes there are a lot of places and I wanted that if the chairs occupied more than 50% of the page, then I had a scroll. I tried to use "overflow-scroll" but it doesn't work. photo of result
<div class="w-50">
<div class="border overflow-scroll">
<div v-for="row in seats" class="d-flex">
<div v-for="seat in row" :key="seat.id" class="seat"></div>
</div>
</div>
</div>
.seat {
width: 50px;
height: 50px;
background: dodgerblue;
border: solid black;
}
same problem using simple html + css (without vue)
index.html
.seat {
width: 50px;
height: 50px;
background: dodgerblue;
border: solid black;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div style="width: 50%;">
<div style="border: solid black; overflow: scroll;">
<div style="display: flex;">
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
</div>
<div style="display: flex;">
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
</div>
</div>
</div>
</body>
</html>
You can use max-width
to limit the viewport. The overflow: scroll
should be the default anyway. The thing is flexbox will adjust the size of the items (shrink, grow).
Just set the items a min-width
or use flex-shrink: 0
.
If you use flex-wrap: nowrap
together with flex-direction: column
or shorthand: flex-flow: column nowrap
for the container (I've added some classes) now, it will grow in width and therefore, since you have set a max-width
of 50%
, the items will overflow and are scrollable.
.seat {
height: 50px;
width: 50px;
flex-shrink: 0;
background: dodgerblue;
border: solid black;
}
.seat-row {
display: flex;
flex: column nowrap;
}
.container {
border: 1px solid black;
overflow: scroll;
max-width: 50%;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="seat-row">
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
</div>
<div class="seat-row">
<div class="seat"></div>
<div class="seat"></div>
<div class="seat"></div>
</div>
</div>
</body>
</html>