Skip to content

Styling guide

The default style sheet contains only enough styles for the bars to be rendered correctly. Bars will have predefined dimensions and a simple sliding transition.

Browser needs to support transition-behavior: allow-discrete to properly handle the transitions. If the browser cannot handle this property, bars will still work fine, just without any transitions.

Animating dialog elements requires the same styles to be applied under multiple selectors. That's why all styles related to the bar dimensions and transitions are defined by using CSS custom properties, under .bartender-bar selector.

INFO

Note that all transitions are disabled if user prefers reduced motion.

Width and height with fallbacks

Width and height related properties have fallback properties, as some browsers don't support dvw or dvh units. If you redefine width or height (or max-width/max-height) using those units, remember to set the fallback properties too.

For example, if we want to set bar max-width to 50dvw, we need to style it like this:

css
.mobileNav {
  --max-width: 50dvw;
  --max-width-fallback: 50vw;
}

// Without fallbacks
.mobileNav {
  --max-width: 500px;
}

Global styles for all bars

You may want to define some global styles, which will apply to all the bars.

css
.bartender-bar {
  --transition-duration: 500ms;
  --opacity-leave: 0;
}

// For left positioned bars
.bartender-bar--position-left {
  --overlay-background: maroon;
}

Available CSS custom properties

Dimensions

PropertyDefault valueDescription
--width80dvw (for left and right bars)Width
--width-fallback80vw (for left and right bars)Fallback for width
--max-width400px (for left and right bars)Maximum width
--max-width-fallbackunsetFallback for maximum width
--height40dvh (for top and bottom bars)Height
--height-fallback40vh (for top and bottom bars)Fallback for height
--max-height400px (for top and bottom bars)Maximum height
--max-height-fallbackunsetFallback for maximum height

Transform and animate

PropertyDefault valueDescription
--opacity-enter1Opacity for open bar
--opacity-leave1Opacity for closed bar
--transform-entertranslate(0, 0)Transform for open bar
--transform-leave(depends on bar position)Transform for closed bar
--transition-duration250msGlobal transition duration
--transition-duration-entervar(--transition-duration)Transition duration for open bar
--transition-duration-leavevar(--transition-duration)Transition duration for closed bar
--transition-timing-functioneaseGlobal transition timing function
--transition-timing-function-entervar(--transition-timing-function)Transition timing function for open bar
--transition-timing-function-leavevar(--transition-timing-function)Transition timing function for closed bar
--animation-nameunsetGlobal animation name
--animation-name-entervar(--animation-name)Animation name for open bar
--animation-name-leavevar(--animation-name)Animation name for closed bar
--animation-timing-functionunsetGlobal animation timing function
--animation-timing-function-entervar(--animation-timing-function)Animation timing function for open bar
--animation-timing-function-leavevar(--animation-timing-function)Animation timing function for closed bar
--animation-directionnormalGlobal animation direction
--animation-direction-entervar(--animation-direction)Animation direction for open bar
--animation-direction-leavevar(--animation-direction)Animation direction for closed bar

Overlay shading

PropertyDefault valueDescription
--overlay-background#000Overlay background color
--overlay-opacity0.5Overlay opacity for open bar
--overlay-transition-duration-entervar(--transition-duration-enter)Overlay transition duration for open bar
--overlay-transition-duration-leavevar(--transition-duration-leave)Overlay transition duration for closed bar
--overlay-transition-timing-function-entervar(--transition-timing-function-enter)Overlay transition timing function for open bar
--overlay-transition-timing-function-leavevar(--transition-timing-function-leave)Overlay transition timing function for open bar

Examples

Full screen bar

javascript
// Bar config
{
  position: 'top',
}
css
.full-screen-bar {
  --width: 100dvw;
  --width-fallback: 100vw;
  --max-width: 100dvw;
  --max-width-fallback: 100vw;
  --height: 100dvh;
  --height-fallback: 100vh;
  --max-height: 100dvh;
  --max-height-fallback: 100vh;
  --transition-duration-enter: 500ms;
  --transition-duration-leave: 250ms;
}

Full screen bar


Centered full screen bar

javascript
// Bar config
{
  position: center,
}
css
.centered-full-screen-bar {
  --overlay-opacity: 0.85;
  --transition-duration-enter: 500ms;
  --transition-duration-leave: 250ms;
  text-align: center;
  color: #fff;
  background: transparent;
}

Centered full screen bar


Bar with animation

In addition to transforms, you can also animate the bar with --animation-* properties.

js
{
  position: right,
}
css
@keyframes slide-in {
  0% {
    transform: translateX(800px) scale(0);
    transform-origin: -100% 50%;
    opacity: 0;
  }
  100% {
    transform: translateX(0) scale(1);
    transform-origin: -1800px 50%;
    opacity: 1;
  }
}

@keyframes slide-out {
  0% {
    transform: translateX(0) scale(1);
    transform-origin: -1800px 50%;
    opacity: 1;
  }
  100% {
    transform: translateX(1000px) scale(0);
    transform-origin: -100% 50%;
    opacity: 1;
  }
}

.bar-with-animation {
  --max-width: 500px;
  --transition-duration-enter: 600ms;
  --transition-duration-leave: 400ms;
  --animation-name-enter: slide-in;
  --animation-name-leave: slide-out;
}

Bar with animation

Released under the MIT License.