CSS Architecture
This document describes the stylesheet structure, class-naming convention, and customization points for the <vn-resize-box> component.
1. Single Stylesheet
All component styles live in src/vanilla-resize-box/vanilla-resize-box.css. The file is automatically injected into <head> by the web component on first connection. Multiple <vn-resize-box> elements share a single <link> tag (identified by id="vn-resize-box-css").
2. CSS Class Inventory
| Class | Element | Purpose |
|---|---|---|
vn-resize-box |
Custom element | The sized layout item — display: block, box-sizing: border-box; receives the width/height/min-*/max-* inline styles |
.vn-resize-box |
Wrapper div | Structural container — position: relative, box-sizing: border-box, overflow: auto |
.vn-resize-handle |
Handle div | Drag handle in the bottom inline-end corner — position: absolute, touch-action: none, cursor: se-resize (sw-resize in RTL) |
.vn-resize-box--dragging |
Wrapper div | Added during active drag — disables child pointer-events, shows resize cursor |
The host element also carries data-theme="<resolved theme>", written by the component (see §7). It is the hook for the per-theme handle rules.
All classes use the vn- prefix to avoid conflicts with host application styles.
3. Custom element (vn-resize-box)
vn-resize-box {
display: block;
box-sizing: border-box;
}
display: block because browsers lay unknown elements out as inline. box-sizing: border-box is a correctness requirement, not a cosmetic default: the drag code measures the element with getBoundingClientRect() — a border-box width — and writes that number straight back into style.width. Under the default content-box, a host that put padding or a border on the custom element would have that chrome added again on every write, inflating the box by twice its chrome on each drag.
4. Container (.vn-resize-box)
.vn-resize-box {
position: relative;
box-sizing: border-box;
overflow: auto;
resize: none;
}
position: relativeanchors the absolutely-positioned handle.overflow: autoallows scrollable content when the box is smaller than its children.resize: nonedisables the browser's native resize affordance (the component provides its own).box-sizing: border-boxensureswidth/heightinclude padding and border.
4.1 Child Sizing & Stacking Containment
.vn-resize-box > :not(.vn-resize-handle) {
width: 100%;
height: 100%;
isolation: isolate;
}
Direct children (except the handle) are stretched to fill the box. This makes it easy to wrap a <vn-grid> or any block element without extra sizing rules.
The component therefore supports exactly one content child. Two direct children each render at the full box height — 2× the box — and overflow into the scrollbars overflow: auto then produces. This is a contract, not a bug to work around: a host that needs several elements wraps them in a single <div> and lays them out inside it.
isolation: isolate makes each content child an atomic stacking layer at z-index: auto. Every z-index the child uses internally (e.g. a grid's custom scrollbar tracks at z-index: 10) is resolved inside that layer and can no longer compete with the sibling .vn-resize-handle — so the handle's z-index: 1 always wins the paint order and pointer hit test in the bottom-right corner, regardless of what the child renders there. Without it, any positioned child descendant with z-index ≥ 1 in that corner would cover the handle and make the resize affordance unreachable.
5. Handle (.vn-resize-handle)
.vn-resize-handle {
position: absolute;
inset-inline-end: 0;
inset-block-end: 0;
width: var(--vn-resize-box-handle-size, 24px);
height: var(--vn-resize-box-handle-size, 24px);
pointer-events: auto;
touch-action: none;
cursor: se-resize;
overflow: hidden;
border-radius: 0 0 5px 0;
z-index: 1;
}
The handle is a 24×24px hotspot (--vn-resize-box-handle-size) pinned to the bottom corner on the inline-end side. z-index: 1 is sufficient to keep it above any content child because children are stacking-isolated (see §4.1) — do not raise it defensively.
touch-action: none is required, not decorative. The drag runs on Pointer Events, so without it the browser claims a touch on the handle for panning and the gesture scrolls the page instead of resizing the box.
inset-inline-end / inset-block-end are logical, so the handle moves to the bottom-left corner under dir="rtl" with no extra rule — see §5.3.
5.1 Glyph (masked icon)
.vn-resize-handle::before {
content: '';
position: absolute;
inset: 0;
background-color: var(--vn-resize-box-handle-color, rgba(128, 128, 128, 0.16));
-webkit-mask: var(--vn-resize-box-handle-icon, url("data:image/svg+xml,…<path d='M24 0V24H0Z'/>…")) center / 100% 100% no-repeat;
mask: var(--vn-resize-box-handle-icon, url("data:image/svg+xml,…")) center / 100% 100% no-repeat;
}
The glyph is a color cut to an icon by a CSS mask, the same pattern the toolbar uses for its command icons. The icon is an SVG url() in a custom property, so a theme swaps both the icon and its colors with CSS only. The default icon is a triangle covering the bottom-right half of a 24×24 viewBox, which renders the same pixels as the gradient the handle used before the mask. The mask is stretched to the handle (100% 100%), so the glyph scales with --vn-resize-box-handle-size.
5.2 Hover/Active Feedback
.vn-resize-handle:hover::before,
.vn-resize-handle:active::before {
background-color: var(--vn-resize-box-handle-hover-color, rgba(80, 120, 220, 0.28));
}
On hover or while pressed only the color changes; the icon stays.
5.3 RTL Mirroring
Logical insets move the handle to the correct corner on their own. Three things are physical and are mirrored by hand:
[dir="rtl"] .vn-resize-handle {
cursor: sw-resize;
border-radius: 0 0 0 5px;
}
[dir="rtl"] .vn-resize-handle::before {
transform: scaleX(-1);
}
[dir="rtl"] .vn-resize-box--dragging {
cursor: sw-resize;
}
Every glyph is drawn for the bottom-right corner, so one horizontal mirror turns any icon, built-in or custom, into its bottom-left counterpart.
These key off the dir attribute, so an RTL host must set dir="rtl" — on <html>, on the box, or on any ancestor — rather than only the CSS direction property. The JavaScript half reads computed direction, which is the honest source for the drag arithmetic; a host that sets direction without dir still resizes correctly but keeps the LTR cursor and glyph.
Only the inline axis mirrors. Vertical writing modes are not supported.
5.4 Forced Colors
@media (forced-colors: active) {
.vn-resize-handle::before {
forced-color-adjust: none;
background-color: CanvasText;
}
.vn-resize-handle:hover::before,
.vn-resize-handle:active::before {
background-color: Highlight;
}
}
Forced-colors mode (Windows high contrast) replaces background colors, which would erase a glyph painted as a masked background. The glyph opts out of the adjustment and is painted in system colors instead, for every theme.
6. Dragging State (.vn-resize-box--dragging)
.vn-resize-box--dragging {
cursor: se-resize;
}
.vn-resize-box--dragging > :not(.vn-resize-handle) {
pointer-events: none;
}
During an active drag:
- The entire container shows
se-resizecursor (not just the handle), so the cursor doesn't flicker if the pointer moves slightly off the handle. - Child elements have
pointer-events: noneto prevent accidental clicks, text selection, or iframe capture while dragging.
7. Handle Theming
7.1 Custom properties
| Property | Default | Meaning |
|---|---|---|
--vn-resize-box-handle-icon |
SVG of the bottom-right triangle | Glyph, used as a mask. Any url() |
--vn-resize-box-handle-color |
rgba(128, 128, 128, 0.16) |
Glyph color, idle |
--vn-resize-box-handle-hover-color |
rgba(80, 120, 220, 0.28) |
Glyph color on hover and while pressed |
--vn-resize-box-handle-size |
24px |
Side of the square hit area; the glyph scales with it |
The defaults live in var() fallbacks inside the handle rules, never as declarations on vn-resize-box itself. A declaration on the host would block a value the page sets on :root or any ancestor; the fallbacks let such a value reach every unthemed box.
7.2 Theme resolution and data-theme
The component writes the resolved theme name to data-theme on the host: its own theme attribute, else the theme attribute of the first descendant <vn-grid>, else default (see 02-web-component-implementation.md §4.5). The stylesheet keys every theme off that attribute, so the scope is the box, not the page: two boxes with different themes each render their own handle.
7.3 Built-in themes
vanilla-resize-box.css holds one block per built-in theme, setting only the icon and the two colors. default has no block; it is the fallbacks. Each dark theme shares its light twin's icon, and the Apple pair shares Material's two strokes, the grip macOS and iOS draw too.
| Theme | Icon | Idle color | Hover color |
|---|---|---|---|
default |
triangle | rgba(128,128,128,.16) |
rgba(80,120,220,.28) |
default-dark |
triangle | rgba(165,169,201,.55) |
rgba(163,177,255,.7) |
material / -dark |
two diagonal strokes, round caps | #5f6368 / #9aa0a6 |
#1a73e8 / #8ab4f8 |
fluent / -dark |
staircase of 6 outlined round dots | #616161 / #adadad |
#0f6cbd / #479ef5 |
carbon / -dark |
staircase of 6 filled squares | #525252 / #a8a8a8 |
#0f62fe / #78a9ff |
fiori / -dark |
staircase of 6 outlined squares | #6a6d70 / #d3d7d9 |
#0a6ed1 / #91c8f6 |
glow / -dark |
two nested corner brackets | #6b7280 / #9ca3af |
#6366f1 / #818cf8 |
apple / -dark |
two diagonal strokes, round caps | rgba(60,60,67,.6) / rgba(235,235,245,.6) |
#007aff / #0a84ff |
ledger |
dog-eared page corner: outlined triangle and fold line | #6b6458 |
#8c2f39 |
Colors reuse each theme's toolbar tokens (muted color idle, accent on hover). Every idle color except default's reaches at least 3:1 against the theme's grid surface (WCAG 1.4.11): the handle is the only sign the box can be resized. default keeps its original subtle look on purpose.
7.4 A host theme
A host theme is one rule, no JS and no registration. It works for any name the box resolves, including a custom grid theme registered with VanillaGridElement.registerTheme():
vn-resize-box[data-theme="corporate"] {
--vn-resize-box-handle-icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'><path d='M20 8 8 20'/><path d='M20 14 14 20'/></svg>");
--vn-resize-box-handle-color: #5b6470;
--vn-resize-box-handle-hover-color: #0b5cad;
}
Change the handle through these properties. A background override on .vn-resize-handle::before still paints, but it is cut by the icon mask.
7.5 Adding Visual Chrome to the Box
.vn-resize-box {
border: 1px solid rgba(0, 0, 0, 0.08);
border-radius: 8px;
padding: 6px;
background: #ffffff;
}
The box's own chrome (border, background, padding) is not part of the handle theme; it stays host CSS on .vn-resize-box, scoped with the box's data-theme if it should follow the theme:
vn-resize-box[data-theme="carbon-dark"] .vn-resize-box {
border-color: rgba(255, 255, 255, 0.1);
background: #161616;
}
8. No Shadow DOM Implications
Because the component attaches all elements to the light DOM:
- Standard CSS cascade and specificity rules apply.
- No
::part()or::slotted()selectors are needed. - Existing theme stylesheets (e.g., Vanilla-Grid themes) work transparently inside the resize box.
- Host applications should use sufficiently specific selectors to avoid accidentally styling
.vn-resize-boxelements they don't intend to target (e.g., scope by container ID).