resizable div

  1. Approach 1. resize CSS property
  2. Approach 2. Drag and Drop API
  3. Approach 3. Mouse Events
  4. Approach N. third-party libraries
  5. Refs

Approach 1. resize CSS property

The resize CSS property sets whether an element is resizable, and if so, in which directions.

resize does not apply to the following:

  • Inline elements
  • Block elements for which the overflow property is set to visible

The problem with the CSS3-only method is that only the bottom-right hand corner of the div becomes draggable.

Also note that IE does not support this property.

Approach 2. Drag and Drop API

Beside approach 1, we can also drag a sibling div and resize the div we are interested in.

  1. Set the draggable="true" on the div that you wish to make draggable
  2. Add a listener for the dragstart event
  3. Resize the div in the drag event handler

Note:

  1. This demo works bad on IE.

Approach 3. Mouse Events

This is the best compatible approach.

Approach N. third-party libraries

  1. interact.js

Refs

  1. CSS resize property
  2. Drag Operations - MDN