5.3  Relative Positioning

Sometimes an element has to be positioned next to another one. This could be achieved by retrieving the other element's geometry values and computing the coordinates of the place next to it. This, however, is tedious and not neccessary.

gDesklets supports relative positioning. With relative positioning, you can use the x and y properties to place an element next to another one.

Relative placement is enabled by using the relative-to property.

The three directions available for relative positioning are:

  • x - right to the element
  • y - below the element
  • xy - below right to the element

The new coordinates origin for relative positioning is computed as follows:

  1. Begin at the anchor of the relative element.
  2. For x or xy, move to the right edge of the element.
  3. For y or xy, move to the bottom edge of the element.
  4. This place will be the new coordinates origin.

The origin thus depends on the position of the anchor of the relative element. If the anchor is center, for example, then the new origin will be at the same x or y coordinate as the anchor. This does not affect the xy placement, though.