I've been spending the last few days trying to understand how CSS flexbox and grid works, and trying to use that knowledge in creating a particular UI, with no luck so far. I'm almost at the point of giving up on it.
The UI looks something like this:
+----------+-----------------------+---------------------+-----------------+
| CANVAS-1 | DIV-3 | DIV-5 | DIV-7 |
| | | | |
| | | | |
| | | +-----------------+
| | | | DIV-8 |
+----------+-----------------------+---------------------+ |
| CANVAS-2 | DIV-4 | DIV-6 | |
| | | +----------------[4]
| | | | DIV-9 |
| | | | |
| | | | |
+---------[1]---------------------[2]-------------------[3]----------------+
Ignoring resize capability, I can design this layout without many problems. However, I have to allow resizing as well, and this is where I have failed miserably over the past two weeks now. My constraints are as follows:
- The layout should fill the browser window (
width: 100vw, height: 100vh). - The two rows in the first three columns should have equal heights.
DIV-8should have height equal to its content andDIV-7/9should take up the remaining space equally.CANVAS-1andCANVAS-2should have a width such that aspect ratio of the canvas is maintained (both canvas elements havewidth="1242" height="2208"attributes defined.- Column #3 and #4 should have an initial width of
300px.
Using a nested grid, I can implement this layout just fine. However, I am also supposed to allow the layout to be resized according to the following rules:
- Dragging
[1]to the left should shrink both canvases while keeping their aspect ratios unchanged. Dragging right beyond its initial position should not be allowed. Dragging this line should not affect any other grid lines. - Dragging
[2]should move the grid line to the left or right, such that minimum width ofDIV-3/4is no less than 400px and that ofDIV-5/6is no less than 200px. Dragging this line should not affect any other grid lines. - Dragging
[3]should move the grid line to the left or right, such that minimum width ofDIV-5/6is no less than 200px, and that ofDIV-7/8/9is no less than 400px. Dragging this line should not affect any other grid lines. - Dragging
[4]should move the grid lines betweenDIV-7/8andDIV-8/9up or down, such that height ofDIV-8should remain unchanged, and space will be traded betweenDIV-7andDIV-9. DIV-3/4/5/6/7/8/9should have scrollbars rendered if the content is not completely visible.- All this should be PREFERABLY done in CSS using
resize: horizontal/verticalandgrid-template-cols: auto/minmax/min-content/max-contentetc, without any JavaScript.
Please help me figure out if this is even possible using CSS alone. If not, please point me towards a JavaScript solution to this problem. I've tried and tested a lot of possibilities to achieve this layout using grid and flexboxes, nested up to 3 levels deep, without success. Please help me solve this problem. I'm sure I'll learn new things here. :)
Thanks, Asim