Skip to main content

CSS User Interface

Two CSS user interface properties are covered in this chapter:

  • resize
  • outline-offset

CSS Resize

Whether users can resize an element, and along which direction, depends on the resize property.

You can give it any one of these values:

  • horizontal — only the width can be changed by the user
  • vertical — only the height can be changed by the user
  • both — width and height can both be changed by the user
  • none — the element stays at its size, with no resizing allowed

Resize only width

Only the width of this <div> element can be resized by the user.

Prompt
Create a page with a div element that the user can resize only horizontally (width). The div should have a border, some padding, and sample text. Use the CSS resize property set to horizontal with overflow auto.
Output: complete HTML page

Resize only height

Only the height of this <div> element can be resized by the user.

Prompt
Create a page with a div element that the user can resize only vertically (height). The div should have a border, some padding, and sample text. Use the CSS resize property set to vertical with overflow auto.
Output: complete HTML page

Resize both width and height

The user is free to resize this <div> element in width and in height alike.

Prompt
Create a page with a div element that the user can resize both horizontally and vertically. The div should have a border, some padding, and sample text. Use the CSS resize property set to both with overflow auto.
Output: complete HTML page

Disable resize in textarea

Browsers usually make a <textarea> resizable by default, and the resize property can switch that off.

Prompt
Create a page with a textarea element that has its default resizability disabled using the CSS resize property set to none. Include a label for the textarea.
Output: complete HTML page

CSS Outline Offset

outline-offset puts a transparent gap between an outline and the edge or border of an element.

Note: Outlines and borders differ. An outline sits outside the border, may overlap other content, and does not count toward the element's size, so its total width and height stay the same.

Example

Here outline-offset opens up a gap between the border and the outline.

Prompt
Create a page with two div elements demonstrating the outline-offset property. The first div has a 1px solid black border, a 4px solid red outline, and an outline-offset of 15px. The second div has a 1px solid black border, a 5px dashed blue outline, and an outline-offset of 5px. Both have margins and some text content.
Output: complete HTML page