I have 2 div elements inside another div, and they are displayed as a block each. So div1 ends up right above div2.
I want to add a "bar" of some kind that the user can click and drag which will end up resizing div2, and div1 will be automatically resized by the same amount.
The parent of div1 and div2 has style: display:flex;flex-direction:column;
and div1 has flex-grow:1
so it automatically resizes.
I want the resize bar to be something like this:
How do I add something like this? Also is there any way I can change the look of it in CSS?
In your column flexbox you can use
resize
on one of the divs and adjust the other automatically usingflex-grow
set to one - the downside is that the slider is not very customizeable:resize: vertical
to one of the flex itemsflex: 1
to the other flex item (so that this flex item will adjust automatically in response to the changing height of the other flex item as it is resized)Solution
Instead you can use a
mousedown
listener that registers amousemove
listener that updates theblock-1
height (and reset themouseup
event) - see demo below: