Slide-In Drawer
侧滑抽屉
A secondary panel enters along one edge while the current view stays behind it.
Where to use it
Expose settings, filters, or object details alongside the current view. Enter from the edge closest to the trigger when the secondary task still depends on context in the page behind it.
Practical example
On a shipment dashboard, selecting a row opens a drawer from the right with tracking events. The underlying list stays in view, which helps staff remember which shipment they opened.
AI prompt
Add an edge-aligned drawer for [content]. Translate it in from the viewport edge, allow scrolling inside long content, and give a modal drawer a labeled close control and focus restoration.
Example code
Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.
View HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Slide-In Drawer</title>
<style>
:root {
color-scheme: dark;
--demo-bg: #171629;
--demo-ink: #f8f5ff;
--demo-accent: #b9a6ff;
--demo-muted: #bfbbd3;
font-family: system-ui, sans-serif;
color: var(--demo-ink);
background: var(--demo-bg);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input { font: inherit; }
.demo {
display: grid;
place-items: center;
align-content: center;
min-height: 100vh;
padding: 14px;
overflow: hidden;
background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
}
.demo-button {
border: 1px solid #ffffff3d;
border-radius: 7px;
background: #ffffff12;
color: var(--demo-ink);
padding: 6px 11px;
font-size: 12px;
cursor: pointer;
}
:focus-visible {
outline: 2px solid var(--demo-accent);
outline-offset: 3px;
}
.example { width: min(100%, 228px); position: relative; display: grid; gap: 10px; }
.panel { background: #292240; border: 1px solid #675785; border-radius: 11px; padding: 10px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.label { margin: 0; font-size: 13px; font-weight: 650; }
.detail, .caption { margin: 0; color: #d7cbea; font-size: 11px; line-height: 1.35; }
.caption { text-align: center; }
.control { border: 1px solid #8874ae; background: #392e57; border-radius: 7px; padding: 5px 9px; min-height: 32px; color: #f6efff; cursor: pointer; font-size: 11px; font-weight: 650; }
.control:hover { background: #514174; }
.control.primary { color: #261b3f; background: #d1bfff; border-color: #e3d8ff; }
.control.primary:hover { background: #e3d8ff; }
.control:disabled { opacity: .55; cursor: default; }
.field { width: 100%; min-width: 0; padding: 6px 8px; border: 1px solid #875fa8; border-radius: 6px; color: #f6efff; background: #1e1732; font-size: 12px; }
.field::placeholder { color: #c2abd8; }
[hidden] { display: none !important; }
.overlay { position: fixed; border: 1px solid #a489d8; border-radius: 11px; padding: 13px; width: 174px; max-width: calc(100% - 22px); background: #302445; color: #fff; box-shadow: 0 12px 30px #120923b0; inset: 0 0 0 auto; margin: 0; min-height: 100%; border-radius: 11px 0 0 11px; }
.overlay[open] { animation: enter .24s ease both; }
.overlay::backdrop { background: #130c25a8; }
.overlay p { margin: 0 0 8px; }
@keyframes enter { from { opacity: 0; transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) {
.example *, .example *::before, .example *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
</style>
</head>
<body>
<main class="demo">
<div class="example"><div class="panel row"><p class="label">Preferences</p><button class="control primary" type="button" aria-haspopup="dialog" data-open>Open</button></div>
<dialog class="overlay" aria-labelledby="overlay-title"><p class="label" id="overlay-title">Layout</p><p class="detail">Adjust how panels are arranged.</p><button class="control" type="button" autofocus>Close</button></dialog></div>
</main>
<script>
const overlay = document.querySelector('.overlay');
const open = document.querySelector('[data-open]');
open.addEventListener('click', () => overlay.showModal());
overlay.querySelector('button').addEventListener('click', () => overlay.close());
overlay.addEventListener('close', () => open.focus());
</script>
</body>
</html>Original example by UI Skills