3

I am creating a web and need to make a scroller appear. I tried using overflow: auto, but then other problem appeared. Here is a simple example of my problem. I have outer div with property overflow: auto and component in angular4 (or in other words another div) that has new background color. When scroller appears and I scroll to right background color disappears. How to have scroller and background color to stay?

.outer {

    width: 110px;
    height: 110px;
    border: thin solid black;
    overflow: auto;
    background: red;
}
.inner{
background:Yellow;

}
<div class="outer">
  <div class="inner">
    <p>
 Scroll to right -> ********************************************
    </p>
  </div>
</div>

2 Answers 2

5

add this: width: fit-content;

.outer {
  width: 110px;
  height: 110px;
  border: thin solid black;
  overflow: auto;
  background: red;
}

.inner {
  background: Yellow;
  width: fit-content;
}
<div class="outer">
  <div class="inner">
    <p>
      Scroll to right -> ********************************************
    </p>
  </div>
</div>

Sign up to request clarification or add additional context in comments.

Comments

1

You can set the inner div to display: inline-block;, so that the width won't get limited by the container's width. Also add min-width: 100%; as needed.

.outer {
  width: 110px;
  height: 110px;
  border: thin solid black;
  overflow: auto;
  background: red;
}

.inner {
  background: yellow;
  display: inline-block;
}

.inner p {
  margin: 0;
}
<div class="outer">
  <div class="inner">
    <p>
      Scroll to right -> ********************************************
    </p>
  </div>
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.