I have two divs side by side. If there is any simple solution, allow the user to resize the width of both divs by dragging.
If the width of one div increases, the width of the other div decreases, keeping the sum of the widths of the two divs unchanged.
It would be great if it could be implemented using pure javascript or css. Feel free to add any other items like divs.
The codes for the two divs are as follows:
.left { float: left; width: 49%; min-height: 50px; border: 2px dashed #f0f } .right { float: right; width: 49%; min-height: 50px; border: 2px dashed #00f }
Thanks for any ideas!
Out of curiosity, I created a little experiment and discovered using a main flexbox container
.wrapper
to contain.left
and.right
elements and make the hard work ofFlexbox Mechanismeasier to implement.Two things:
resize
, the propertyoverflow
needs to be set toauto
to make thehandlevisible (in Windows Firefox and Chrome/Edge The above test passed)..left
. Because they are children of the flexbox, when usingflex: 1
(.right
) on another element, theflexbox mechanismwill make that element Follows the size of the resized element and fills any remaining space.MDN Reference: resize