I want to have a following page structure:
----------------------------------------
| |s| |
| top-content |p| details |
|--------------|l| |
|s | tree |i| |
|c | |t| |
|r | |t| |
|o | |e| |
|l | |r| |
|l | | | |
|--|-----------| | |
| | scroll | | |
-----------------------------------
The top content must be ‘fixed’ and always be shown above the tree in the left pane so I use the wrapper.
I have:
.wrapper {
height: 100%;
display: flex;
direction: ltr;
flex-direction: column;
}
.tree-parent-div {
direction: rtl;
overflow: auto;
width: 100%;
height: inherit;
}
.tree-child-div {
height: inherit;
direction: ltr !important;
}
<div class='wrapper'>
<div class='top-content'>Here lies top content</div>
<div class='tree-parent-div'>
<div class='=tree-child-div'>Here lies the js tree</div>
</div>
</div>
I use ‘tree-parent-div’ and ‘tree-child-div’ system instead of using only ‘tree-child-div’ because I need vertical scrollbar to be on the left side.
Here is the dilemma. I want both scrollbars to be in ‘tree-parent-div’. Vertical scrollbar works well.
But when the content of ‘tree-child-div’ is bigger than the width of ‘tree-parent-div’ (for example there is a big number 4152674168794361742343847652361790349568463521678329456584736325145676 in the tree node name), the horizontal scrollbar is not visible.
2
Answers
The
tree-child-div
needs to bedisplay: inline-block;
(or similar).If you want your parent div to not be scrolled to the right initially, change the
direction
property.The issue you’re facing arises from the combination of the
direction: rtl
property and theheight: inherit
property within flex containers. This combination can create unexpected behaviors with scrollbars.To achieve your goal (having both scrollbars inside
tree-parent-div
), you can utilize theoverflow
properties.Here’s a revised solution:
Here’s your HTML structure:
The key change here is adding
width: max-content;
to.tree-child-div
. This ensures that the width of the child div is determined by its content. Theoverflow-x: auto;
on.tree-parent-div
ensures that if the child div overflows the parent in terms of width, the horizontal scrollbar appears on the parent.Note: Ensure you have a fixed height (or max-height) for your
.wrapper
, or ensure it’s contained within an element that has a fixed height, to make sure the vertical scrollbar works as expected.