--- category: Navigation created: '2019-12-13' description: Create a drawer navigation with CSS keywords: css drawer, css off-canvas thumbnail: /assets/css-layout/thumbnails/drawer.png title: Drawer --- This pattern is also known as off-canvas. ## HTML ```html index.html
...
``` ## CSS ```css styles.css .drawer { /* Take full size */ height: 100%; left: 0; position: fixed; top: 0; width: 100%; z-index: 9999; } .drawer__overlay { /* Take full size */ height: 100%; left: 0; position: fixed; top: 0; width: 100%; /* User still can see the content of main page */ background-color: rgba(0, 0, 0, 0.5); z-index: -1; } .drawer__sidebar { /* Take full height */ height: 100%; left: 0; position: fixed; top: 0; width: 200px; /* Background */ background-color: #fff; } ``` ```css placeholders.css hidden .lines { padding: 0.25rem 0; width: 100%; align-items: center; display: flex; justify-content: center; flex-direction: column; } .line { background: #d1d5db; height: 1px; margin-bottom: 0.25rem; } .line.line--20 { width: 20%; } .line.line--40 { width: 40%; } .line.line--60 { width: 60%; } .line.line--80 { width: 80%; } .line.line--100 { width: 100%; } ``` ```css styles.css hidden body { height: 24rem; } .drawer { /* Demo */ border: 1px solid #d1d5db; border-radius: 0.25rem; height: 100%; width: 100%; display: flex; } .drawer__sidebar { /* Demo */ border-right: 1px solid #d1d5db; width: 25%; } .drawer__overlay { /* Demo */ background: #4b5563; flex: 1; } ``` ```html index.html hidden
```