如何迫使div水平而不是垂直连续溢出?

时间:2019-06-28 21:39:01

标签: html css bootstrap-4

我如何强制其水平传播而不是垂直传播?

.imageBottomSheet {
  overflow-y: scroll;
  height: 150px;
}

img {
  padding: 0 5px 0 5px;
  height: 150px;
}

.transparent-button {
  border: 0;
  background: transparent;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />

<body>
  <div class="imageBottomSheet">

    <div class="row">
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>

      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>

      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>

      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>

      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>

      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>

      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>

      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>

      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>


    </div>


  </div>

</body>

1 个答案:

答案 0 :(得分:2)

只需将flex-nowrap添加到行(https://getbootstrap.com/docs/4.3/utilities/flex/#wrap

.imageBottomSheet {
  overflow-y: scroll;
  height: 150px;
}

img {
  padding: 0 5px 0 5px;
  height: 150px;
}

.transparent-button {
  border: 0;
  background: transparent;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />

<body>
  <div class="imageBottomSheet">

    <div class="row flex-nowrap">
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>

      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>

      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>

      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>

      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>

      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>

      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>

      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>

      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>
      <button class="transparent-button">
        <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/10/Winniethepooh.png/220px-Winniethepooh.png">
      </button>


    </div>


  </div>

</body>