Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split pane using CSS3 Resize property

I've been trying to do split pane resizing using the CSS3 property.

Here is the code:

<style>

div.left, div.right {float: left; outline: solid 1px #ccc; 
resize: both; overflow: auto;}

div.left {width: 20%}

div.right {width: 80%}

</style> 

<div class="left"> 
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
</div> 

<div class="right"> 
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. 
</div> 

The problem is if i resize the left div, the right div won't shrink and its being pushed to the bottom. Are there any other ways that I can make the split pane without using the javascript?

Say, if it can't be done using CSS3 and really need to use the javascript, the javascript should be minimal if can.

Thank you.

like image 932
Amirul Avatar asked Sep 21 '10 09:09

Amirul


People also ask

What is resize property in CSS?

The resize property defines if (and how) an element is resizable by the user. Note: The resize property does not apply to inline elements or to block elements where overflow="visible". So, make sure that overflow is set to "scroll", "auto", or "hidden". Default value: none.

How do I make div not move when resized?

first add a parent div/wrap and put those two divs of yours into it. Overall, whatever size you add to the min-width itll scale the parent div down to the size specified. once the window is sized down past your specified size, itll behave like any other window. this is my way of doing it.

How do I resize a div mouse?

The mouse trigger the mousedown event on the resizer. Then catch the mousemove event on the resizer to handle begin to resize. With the bottom-right resizer, when the user drags that resizer, the element's width will equal to the x position of the mouse minus the x position of the element.


1 Answers

I'm not sure why you're expecting the other element to resize - there doesn't appear to be any relationship between them in your markup?

Assuming you're targeting WebKit and Firefox development snapshots, this should do most of what you're interested in:

  1. Create a wrapper element and set it to display: box (using appropriate vendor prefixes)
  2. Set one of your elements to be fixed size but resizable, otherwise things just get too confusing for the browser
  3. Set the other to be box-flex: 1 (again with appropriate vendor prefixes)

Here's a working example, works better in Chrome than Firefox - if you need any other browsers supported then you'll need a JavaScript solution.

--edit:

Just got an upvote on this old answer, the old example doesn't work with the new version of flexbox, so here's a new example. In the above steps replace display: box with display: flex and box-flex: 1 with flex: 1 1 0;.

like image 107
robertc Avatar answered Sep 30 '22 18:09

robertc