Skip to content

Styling

The stylesheet draws the drag states only - the ghost, the chosen item, the preview, the swap target, the selection, the locked items - and leaves the look of your list to you. Every state is tinted with one accent and tuned through custom properties, and each state's class can be replaced with one of your own.

An accent and a few properties

These two lists use the stylesheet's own drag states, with no class of this site's. The controls set the stylesheet's custom properties on the element around them, and the lists inherit them: the accent every state is tinted with, how transparent the dragged item is, and outlines for the lists that take a drag.

--bit-bortable-accent-rgb
Fruit
Apple
Banana
Cherry
Date
Basket
Fig
Grape
.board {
    --bit-bortable-accent-rgb: 13, 110, 253;
    --bit-bortable-ghost-opacity: 0.40;
    --bit-bortable-accepts-outline: 2px dashed rgba(13, 110, 253, .5);
    --bit-bortable-over-outline: 2px solid rgb(13, 110, 253);
}

Classes of your own

GhostClass, ChosenClass and DragClass replace the class of a state with your own, for a list that wants its own look instead of the stylesheet's: here a dashed amber ghost, an amber chosen item, and a tilted preview. The list has ForceFallback, so the mouse drags with the preview too.

.my-ghost  { opacity: .55; outline: 2px dashed var(--bb-warning); outline-offset: -2px; }
.my-chosen { background-color: var(--bb-warning-soft); }
.my-drag   { rotate: -3deg; opacity: .95; outline: 2px solid var(--bb-warning); box-shadow: 0 18px 36px rgba(0, 0, 0, .25); }
One
Two
Three
Four

Order: One, Two, Three, Four

Try it

  • Pick Violet and drag a fruit: the dragged item and its preview in the Basket are tinted violet.
  • Lower the ghost opacity to 0.1: the dragged item almost disappears from its place.
  • Tick the outlines and drag a fruit: both lists are outlined dashed, and the one under the pointer solid.
  • Drag an item of the last list with the mouse: the preview that follows the pointer is tilted, the place it left is dashed. Pick one up from the keyboard: a keyboard drag wears only the chosen class.

Every custom property

Override them on :root for the whole app, on one list's Class, or inline through its Style. The colours are worked out on the item itself, so an accent set on one list reaches its items.

PropertyDefaultUsed for
--bit-bortable-accent-rgb13, 110, 253The accent every state is tinted with, as an r, g, b triplet.
--bit-bortable-ghost-opacity0.4The dragged item and the drop placeholder.
--bit-bortable-chosen-bgthe accent at 12%The chosen item's background.
--bit-bortable-swap-bgthe accent at 18%The swap target's background.
--bit-bortable-swap-outline2px dashed, accent at 60%The swap target's outline.
--bit-bortable-selected-bgthe accent at 25%A multi-drag selected item's background.
--bit-bortable-selected-ringinset 2px, accent at 80%A multi-drag selected item's ring (a box-shadow).
--bit-bortable-filtered-opacity0.7A filtered item.
--bit-bortable-focus-outline2px solid, accent at 90%The outline of an item focused from the keyboard.
--bit-bortable-focus-offset2pxHow far that outline sits outside the item.
--bit-bortable-lifted-outline-styledashedThe outline style of an item picked up from the keyboard.
--bit-bortable-drag-opacity0.92The preview that follows a finger, a pen or a ForceFallback mouse.
--bit-bortable-drag-shadowa soft shadowThat preview's shadow.
--bit-bortable-accepts-outlinenoneDuring a drag, the outline of every list that takes it.
--bit-bortable-over-outlinenoneThe outline of the list under the pointer.
--bit-bortable-refused-outlinenoneThe outline of that list when it refused the position (see rules).
--bit-bortable-target-offset2pxHow far those outlines sit outside the list.

The classes

ClassSet onReplaced by
bit-bortableThe list container.
bit-bortable-itemEvery item wrapper, and the drop placeholder.
bit-bortable-ghostThe item being dragged with a pointer, in its list, and the drop placeholder.GhostClass
bit-bortable-chosenThe item being dragged - also from the keyboard - and the drop placeholder.ChosenClass
bit-bortable-dragThe preview that follows a finger, a pen or a ForceFallback mouse.DragClass
bit-bortable-hiddenThe original of a moved item while it is previewed in another list.
bit-bortable-swap-highlightThe swap target, in swap mode.SwapClass
bit-bortable-selectedThe items of a multi-drag selection.SelectedClass
bit-bortable-filteredItems the Filter locks.
bit-bortable-disabledThe container of a Disabled list.
bit-bortable-has-handleThe container of a list with a Handle.

While a drag runs, the browser layer also sets attributes you can style, at no render cost: data-bortable-accepts on every list that takes the drag, data-bortable-over on the one under the pointer, data-bortable-refused on that one when it refused the position, and data-bortable-dragging on <html>, set to native, pointer or keyboard. Your own look for the list and its items goes through Class and Style on the container and ItemClass and ItemClassSelector on the items.

GhostClass, ChosenClass, DragClass, SwapClass and SelectedClass can also be set once for every list of the app, in the app-wide defaults.
An unhandled error has occurred. Reload 🗙