Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertical scroll bar in div which is a child of css grid column

Tags:

css

css-grid

I am new to CSS grid, I have a nested grid layout page. I could not get a scroll bar for grid child div.fieldsContainer.

html,body,
.wrapper{
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.wrapper{
  display: grid;
  grid-template-rows: 50px 1fr 50px;
}

.header{
  border: 1px solid #ddd;
  background: lightyellow;
}

.footer{
  background: lightpink;
}

.content{
  display: grid;
  grid-template-columns: 250px 1fr 300px;
  grid-gap: 10px;
  overflow: hidden;
}

.fieldTypes{
  display: grid;
  grid-template-rows: 40px 1fr;
}

.fieldTypes .search{
  border: 1px solid red;
}

.fieldTypes .fieldsContainer{
  display: grid;
  grid-template-columns: repeat(3, minmax(70px,1fr));
  grid-auto-rows: 50px;
  grid-gap: 10px;
}

.card{
  padding: 10px;
  background: #ddd;
}
<div class="wrapper">
  <div class="header">
    Header
  </div>
  <div class="content">
    <div class="fieldTypes">
      <div class="search">search</div>
      <div class="fieldsContainer">
        <div class="card">1</div>
        <div class="card">2</div>
        <div class="card">3</div>
        <div class="card">4</div>
        <div class="card">5</div>
        <div class="card">6</div>
        <div class="card">7</div>
        <div class="card">8</div>
        <div class="card">9</div>
        <div class="card">10</div>
        <div class="card">11</div>
        <div class="card">12</div>
        <div class="card">10</div>
        <div class="card">11</div>
        <div class="card">12</div>
        <div class="card">10</div>
        <div class="card">11</div>
        <div class="card">12</div>
      </div>
    </div>
    <div class="inndercontent">
      innder content
    </div>
    <div class="graphs">
      graphs
    </div>
  </div>
  <div class="footer">
    Footer
  </div>
</div>
like image 716
Saravanan Ramupillai Avatar asked Mar 19 '18 12:03

Saravanan Ramupillai


People also ask

How do I vertically scroll in CSS?

For vertical scrollable bar use the x and y axis. Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable.

What is grid column in CSS?

The grid-column CSS shorthand property specifies a grid item's size and location within a grid column by contributing a line, a span, or nothing (automatic) to its grid placement, thereby specifying the inline-start and inline-end edge of its grid area.

What is grid Container Div?

5 months ago. by Naima Aftab. A CSS grid is regarded as a layout model that partitions a web page into various rows and columns to arrange elements. These rows and columns help in aligning elements easily rather than using position and float properties.


1 Answers

Here's a more reduced case (to cut through the irrelevant parts)

html, body, .A {
  height: 100%; /* matters */
  width: 100%;
  margin: 0;
  padding: 0;
}

.A {
  max-height: 300px; /* matters */
  display: grid; /* matters */
  overflow: hidden; /* matters */
}

.B {
  display: grid; /* matters */
  overflow-y: auto; /* matters */
}

.D {
  overflow-y: scroll; /* matters */
}

.C {
  padding: 10px;
  background-color: #07f;
}

.E {
  padding: 10px;
  background-color: #eee;
}
<div class="A">
  <div class="B">
    <div class="C">search</div>
    <div class="D">
      <div class="E">1</div>
      <div class="E">2</div>
      <div class="E">3</div>
      <div class="E">4</div>
      <div class="E">5</div>
      <div class="E">6</div>
      <div class="E">7</div>
      <div class="E">8</div>
      <div class="E">9</div>
      <div class="E">10</div>
      <div class="E">11</div>
      <div class="E">12</div>
      <div class="E">10</div>
      <div class="E">11</div>
      <div class="E">12</div>
      <div class="E">10</div>
      <div class="E">11</div>
      <div class="E">12</div>
    </div>
  </div>
</div>
like image 62
Stephen Avatar answered Oct 06 '22 00:10

Stephen