1

I have following code

.parent {
  display: flex;
  width: 100%;
  flex-direction: column;
  overflow-x: auto;
}
.child {
  display: flex;
  flex-flow: row nowrap;
  background: red;
}
.grand-child {
  flex-shrink: 0;
  display: block;
  align-items: center;
  padding: .54rem 1.05rem;
  width: 300px;
  height: 100px;
  overflow-x: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
<div class="parent">
  <div class="child">
    <div class="grand-child">a</div>
    <div class="grand-child">b</div>
    <div class="grand-child">c</div>
    <div class="grand-child">d</div>
  </div>
</div>

DEMO

Problem: When a background is applied to the class .children, the background is not overflowed content (When scrolling through x axis). I want to keep the scrollability as it is while applying the background only to .children class. If that is not possible what is the reason?

I had this question while answering This. Though I managed to provide a fix for the issue this specific problem still remains

Sam C.
  • 66
  • 5

2 Answers2

1

it just because of the flex-shrink: 0; property on your grand-child class.please remove that if you want to align your all grand-childs inside the child class.

.parent {
  display: flex;
  width: 100%;
  flex-direction: column;
  overflow-x: auto;
}
.child {
  display: flex;
  flex-flow: row nowrap;
  background: red;
  width:1200px;
}
.grand-child {
  /*flex-shrink: 0;*/
  display: block;
  align-items: center;
  padding: .54rem 1.05rem;
  width: 300px;
  height: 100px;
  overflow-x: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
<div class="parent">
  <div class="child">
    <div class="grand-child">a</div>
    <div class="grand-child">b</div>
    <div class="grand-child">c</div>
    <div class="grand-child">d</div>
  </div>
</div>
ADH - THE TECHIE GUY
  • 4,125
  • 3
  • 31
  • 54
0

let's check that code.

https://jsfiddle.net/2cuqL1f3/7/

css:

.child {
  background: red;
  width:100%;
  height:100px;
  overflow:scroll;
  white-space: nowrap;
}
.grand-child {

  display: inline-block;
  min-width: 300px;
  height: 100px;
  overflow-x: hidden;
}
MarkFroog
  • 21
  • 1
  • 2
  • 3