0

I have a div with class name graph-container with the following properties:

.graph-container{
    width: 90%;
    height: 298px;
    padding: 20px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

and in that div, among other things, I have another div with the class graph-selector which contains a list of buttons:

.graph-selector{
    display: flex;
    flex-direction: column;
    gap: 2px;
    height: 100%;
    width: 320px;
    margin-top: 46px;
    overflow-y: auto;
    overflow-x: hidden;
}

Depending on the graph, it can have a few, or a lot of buttons, so I set the vertical overflow property to add a scrollbar whenever they would extend the size of the container div. However for some reason this just made the buttons thinner than their set height to be able to be squeezed into the container div without any scrollbar appearing, which is... literally the opposite of what I just asked it?

2
  • Can you clarify if the class .graph-selector is inside the .graph-container class, if so, remove the height property 100% in .graph-selector Commented Feb 27 at 10:53
  • 1
    Yes, I literally said it's inside. Removing the height property just makes the inner div spill on the content above and under, still without a scrollbar... Commented Feb 27 at 11:52

1 Answer 1

2

You can prevent shrink by adding flex-shrink: 0 to the buttons [MDN].

.graph-container {
  width: 90%;
  height: 50px;
  padding: 20px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.graph-selector {
  display: flex;
  flex-direction: column;
  gap: 2px;
  height: 100%;
  width: 320px;
  margin-top: 46px;
  overflow-y: auto;
  overflow-x: hidden;
}

.graph-selector-btn {
  height: 40px;
  flex-shrink: 0;
}
<div class="graph-container">
  <div class="graph-selector">
    <button class="graph-selector-btn">Button 1</button>
    <button class="graph-selector-btn">Button 2</button>
    <button class="graph-selector-btn">Button 3</button>
  </div>
</div>

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

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.