Home > Blockchain >  "overflow: scroll" add scroll that can't be scrolled
"overflow: scroll" add scroll that can't be scrolled

Time:12-30

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 >
    <div >
      <div v-for="row in seats" >
        <div v-for="seat in row" :key="seat.id" ></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 ></div>
        <div ></div>
        <div ></div>
        <div ></div>
        <div ></div>
        <div ></div>
        <div ></div>
        <div ></div>
        <div ></div>
      </div>
      <div style="display: flex;">
        <div ></div>
        <div ></div>
        <div ></div>
      </div>
    </div>
  </div>
</body>

</html>

CodePudding user response:

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 >
    <div >
      <div ></div>
      <div ></div>
      <div ></div>
      <div ></div>
      <div ></div>
      <div ></div>
      <div ></div>
      <div ></div>
      <div ></div>
      <div ></div>
      <div ></div>
      <div ></div>
      <div ></div>
      <div ></div>
    </div>
    <div >
      <div ></div>
      <div ></div>
      <div ></div>
    </div>
  </div>
</body>

</html>

  • Related