CSS Horizontal Scrolling code example

Example 1: horizontal scroll html

<div class="scrolling-wrapper">
  <div class="card"><h2>Card</h2></div>
  <div class="card"><h2>Card</h2></div>
  <div class="card"><h2>Card</h2></div>
  <div class="card"><h2>Card</h2></div>
  <div class="card"><h2>Card</h2></div>
  <div class="card"><h2>Card</h2></div>
  <div class="card"><h2>Card</h2></div>
  <div class="card"><h2>Card</h2></div>
  <div class="card"><h2>Card</h2></div>
</div>
.scrolling-wrapper {
  overflow-x: scroll;
  overflow-y: hidden;
  white-space: nowrap;

  .card {
    display: inline-block;
  }
}

Example 2: how to make div scrollable horizontal

overflow-x: auto(show when needed) or hidden(never) or scroll(always scroll);

Example 3: horizontal scroll

.scrolling-wrapper-flexbox {  display: flex;  flex-wrap: nowrap;  overflow-x: auto;  .card {    flex: 0 0 auto;  }}

Tags:

Css Example