1
0
mirror of https://github.com/phuoc-ng/csslayout.git synced 2025-08-06 06:07:33 +02:00
Files
csslayout/contents/full-screen-menu.mdx
2023-10-06 18:20:10 +07:00

170 lines
2.9 KiB
Plaintext

---
category: Navigation
created: '2019-11-30'
description: Create a full screen menu with CSS flexbox
keywords: css fixed, css flexbox, css menu
thumbnail: /assets/css-layout/thumbnails/full-screen-menu.png
title: Full screen menu
---
## HTML
```html index.html
<div class="full-screen-menu">
<!-- The navigation menu -->
<ul>
...
</ul>
<!-- The close button -->
<button type="button" class="full-screen-menu__close"></button>
</div>
```
## CSS
```css styles.css
.full-screen-menu {
/* Full screen overlay */
height: 100%;
left: 0;
position: fixed;
top: 0;
width: 100%;
/* Center the content */
align-items: center;
display: flex;
justify-content: center;
}
.full-screen-menu__close {
/* Shown at top left corner */
left: 1rem;
position: absolute;
top: 1rem;
}
```
You can use the [close button](https://phuoc.ng/collection/css-layout/close-button/) to create a button for closing the menu.
<Playground>
```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;
}
.full-screen-menu {
/* Take full size */
height: 100%;
width: 100%;
/* Center the content */
align-items: center;
display: flex;
justify-content: center;
position: relative;
background: #374151;
}
.full-screen-menu__close {
left: 0.5rem;
position: absolute;
top: 0.5rem;
/* Reset */
background-color: transparent;
border-color: transparent;
/* Cursor */
cursor: pointer;
/* Size */
height: 1rem;
width: 1rem;
}
.full-screen-menu__close::before,
.full-screen-menu__close::after {
content: '';
/* Background color */
background-color: #d1d5db;
/* Position */
position: absolute;
/* Size */
height: 1px;
width: 100%;
}
.full-screen-menu__close::before {
/* Position */
left: 0px;
top: 50%;
transform: translate(0%, -50%) rotate(45deg);
/* Size */
height: 1px;
width: 100%;
}
.full-screen-menu__close::after {
/* Position */
left: 50%;
top: 0px;
transform: translate(-50%, 0%) rotate(45deg);
/* Size */
height: 100%;
width: 1px;
}
```
```html index.html hidden
<div class="full-screen-menu">
<div class="lines">
<div class="line line--80"></div>
<div class="line line--40"></div>
<div class="line line--100"></div>
<div class="line line--60"></div>
<div class="line line--20"></div>
</div>
<button type="button" class="full-screen-menu__close"></button>
</div>
```
</Playground>