示例工程 56-responsive-nav
56-responsive-nav/demo-02-drawer/style.css
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
:root {
--ink: #0f172a;
--muted: #64748b;
--border: #e2e8f0;
--brand: #4f46e5;
--brand-soft: #e0e7ff;
}
body {
margin: 0;
background: #f8fafc;
color: var(--ink);
font-family: system-ui, sans-serif;
line-height: 1.7;
}
.content {
padding: 48px 24px;
}
h1 { margin: 0 0 4px; font-size: 28px; }
p { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.trigger {
min-height: 44px;
padding: 0 18px;
border: 1px solid var(--brand);
border-radius: 8px;
background: var(--brand);
color: #ffffff;
font: inherit;
font-size: 14px;
cursor: pointer;
}
.trigger:focus-visible,
.drawer a:focus-visible,
.close:focus-visible {
outline: 3px solid #b45309;
outline-offset: 2px;
}
.drawer {
position: fixed;
inset: 0 auto 0 0;
width: min(86vw, 340px);
max-width: none;
height: 100dvh;
max-height: none;
margin: 0;
padding: 0;
border: 0;
background: #ffffff;
}
.drawer::backdrop {
background: rgb(15 23 42 / 45%);
}
.drawer-head {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px;
border-bottom: 1px solid var(--border);
font-size: 12px;
}
.close {
display: inline-flex;
align-items: center;
justify-content: center;
width: 44px;
height: 44px;
border: 1px solid var(--border);
border-radius: 50%;
background: #ffffff;
color: var(--ink);
font: inherit;
font-size: 20px;
cursor: pointer;
}
.drawer nav {
display: grid;
gap: 2px;
padding: 8px;
}
.drawer nav a {
display: flex;
align-items: center;
min-height: 44px;
padding: 0 12px;
border-radius: 8px;
color: var(--ink);
font-size: 15px;
text-decoration: none;
}
.drawer nav a:hover,
.drawer nav a:focus-visible {
background: var(--brand-soft);
color: #3730a3;
}
body:has(.drawer[open]) {
overflow: hidden;
}