Toggle navigation
☰
Home
HTML
CSS
Scripting
Database
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>The Circular/Radial Menu</title> <style> :root { --menu-size: 60px; /* The size of the main button */ --menu-item-size: 50px; --menu-radius: 150px; /* How far the items fly out */ --color-background: #f4f4f5; --color-primary: #6d28d9; --color-primary-light: #8b5cf6; --color-surface: #ffffff; --color-text-light: #ffffff; --color-text-dark: #374151; --transition-speed: 0.4s; --transition-curve: cubic-bezier(0.68, -0.55, 0.27, 1.55); /* Bouncy */ } body { margin: 0; font-family: sans-serif; background-color: var(--color-background); } .content { min-height: 150vh; padding: 2rem; } /* ======================================== The Main Menu Container ======================================== Fixed to the bottom-right of the screen. */ .radial-menu { position: fixed; bottom: 2rem; right: 2rem; width: var(--menu-size); height: var(--menu-size); z-index: 1000; } /* The invisible checkbox that tracks the menu's state (open/closed) */ #menu-toggle-checkbox { display: none; } /* ======================================== The Main Menu Button (The Label) ======================================== This is what the user clicks. */ .menu-toggle-label { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: var(--color-primary); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--color-text-light); cursor: pointer; box-shadow: 0 4px 15px rgba(0,0,0,0.2); transition: transform var(--transition-speed) ease; z-index: 2; /* Sits above the menu items */ } .menu-toggle-label:hover { background-color: var(--color-primary-light); } /* The 'plus' icon and its transition to an 'X' */ .icon-open, .icon-close { position: absolute; width: 24px; height: 24px; transition: transform 0.3s ease, opacity 0.3s ease; } #menu-toggle-checkbox:checked + .menu-toggle-label .icon-open { transform: rotate(45deg); opacity: 0; } #menu-toggle-checkbox:checked + .menu-toggle-label .icon-close { transform: rotate(0); opacity: 1; } .icon-close { opacity: 0; transform: rotate(-45deg); } /* ======================================== The Navigation Links (Menu Items) ======================================== */ .menu-items { list-style: none; margin: 0; padding: 0; } .menu-item { position: absolute; top: 5px; left: 5px; /* Centered with the main button */ width: var(--menu-item-size); height: var(--menu-item-size); /* Hidden by default and positioned in the center */ opacity: 0; transform: translate(0, 0) scale(0.5); transition: transform var(--transition-speed) var(--transition-curve), opacity var(--transition-speed) var(--transition-curve); pointer-events: none; z-index: 1; } .menu-item a { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; background-color: var(--color-surface); color: var(--color-text-dark); border-radius: 50%; box-shadow: 0 2px 8px rgba(0,0,0,0.15); } .menu-item a:hover { background-color: #f9fafb; } .menu-item svg { width: 24px; height: 24px; } /* ======================================== Open State and Circular Positioning ======================================== When the checkbox is checked, this block becomes active. */ #menu-toggle-checkbox:checked ~ .menu-items .menu-item { opacity: 1; pointer-events: auto; /* Make items clickable */ } /* ======================================== The magic happens here ======================================== These angles are for a menu in the bottom-right corner, fanning out up and to the left. */ /* Item 1: Positioned at 90 degrees */ #menu-toggle-checkbox:checked ~ .menu-items .menu-item:nth-child(1) { transform: translateY(calc(-1 * var(--menu-radius))); } /* Item 2: Positioned at 112.5 degrees */ #menu-toggle-checkbox:checked ~ .menu-items .menu-item:nth-child(2) { transform: translate(calc(-0.383 * var(--menu-radius)), calc(-0.924 * var(--menu-radius))); } /* Item 3: Positioned at 135 degrees */ #menu-toggle-checkbox:checked ~ .menu-items .menu-item:nth-child(3) { transform: translate(calc(-0.707 * var(--menu-radius)), calc(-0.707 * var(--menu-radius))); } /* Item 4: Positioned at 157.5 degrees */ #menu-toggle-checkbox:checked ~ .menu-items .menu-item:nth-child(4) { transform: translate(calc(-0.924 * var(--menu-radius)), calc(-0.383 * var(--menu-radius))); } /* Item 5: Positioned at 180 degrees */ #menu-toggle-checkbox:checked ~ .menu-items .menu-item:nth-child(5) { transform: translateX(calc(-1 * var(--menu-radius))); } </style> </head> <body> <div class="content"> <h1>Circular/Radial Menu</h1> <p>Click the button in the bottom-right corner to see the menu items fan out.</p> </div> <div class="radial-menu"> <input type="checkbox" id="menu-toggle-checkbox"> <label for="menu-toggle-checkbox" class="menu-toggle-label"> <svg class="icon-open" viewBox="0 0 24 24"><path fill="currentColor" d="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z" /></svg> <svg class="icon-close" viewBox="0 0 24 24"><path fill="currentColor" d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z" /></svg> </label> <ul class="menu-items"> <li class="menu-item"><a href="#" aria-label="Home"><svg viewBox="0 0 24 24"><path fill="currentColor" d="M10,20V14H14V20H19V12H22L12,3L2,12H5V20H10Z" /></svg></a></li> <li class="menu-item"><a href="#" aria-label="Search"><svg viewBox="0 0 24 24"><path fill="currentColor" d="M9.5,3A6.5,6.5 0 0,1 16,9.5C16,11.11 15.41,12.59 14.44,13.73L14.71,14H15.5L20.5,19L19,20.5L14,15.5V14.71L13.73,14.44C12.59,15.41 11.11,16 9.5,16A6.5,6.5 0 0,1 3,9.5A6.5,6.5 0 0,1 9.5,3M9.5,5C7,5 5,7 5,9.5C5,12 7,14 9.5,14C12,14 14,12 14,9.5C14,7 12,5 9.5,5Z" /></svg></a></li> <li class="menu-item"><a href="#" aria-label="Settings"><svg viewBox="0 0 24 24"><path fill="currentColor" d="M12,8A4,4 0 0,1 16,12A4,4 0 0,1 12,16A4,4 0 0,1 8,12A4,4 0 0,1 12,8M12,10A2,2 0 0,0 10,12A2,2 0 0,0 12,14A2,2 0 0,0 14,12A2,2 0 0,0 12,10M10,22C9.75,22 9.5,21.9 9.32,21.72L5.82,18.22C5.64,18.04 5.56,17.79 5.56,17.53C5.56,17.28 5.64,17.03 5.82,16.85L8.35,14.32L9.76,15.73L6.96,18.53L10.46,22L10,22M22,10C22,9.75 21.9,9.5 21.72,9.32L18.22,5.82C18.04,5.64 17.79,5.56 17.53,5.56C17.28,5.56 17.03,5.64 16.85,5.82L14.32,8.35L15.73,9.76L18.53,6.96L22,10.46L22,10Z" /></svg></a></li> <li class="menu-item"><a href="#" aria-label="Mail"><svg viewBox="0 0 24 24"><path fill="currentColor" d="M20,8L12,13L4,8V6L12,11L20,6M20,4H4C2.89,4 2,4.89 2,6V18A2,2 0 0,0 4,20H20A2,2 0 0,0 22,18V6C22,4.89 21.1,4 20,4Z" /></svg></a></li> <li class="menu-item"><a href="#" aria-label="Profile"><svg viewBox="0 0 24 24"><path fill="currentColor" d="M12,12A5,5 0 0,0 17,7A5,5 0 0,0 12,2A5,5 0 0,0 7,7A5,5 0 0,0 12,12M12,14C9.33,14 4,15.33 4,18V20H20V18C20,15.33 14.67,14 12,14Z" /></svg></a></li> </ul> </div> </body> </html>