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>Button Group</title> <style> /* Component: Button Group Description: A set of related buttons that are visually joined together. */ :root { --btn-group-border-color: #007bff; --btn-group-bg: #ffffff; --btn-group-text-color: var(--btn-group-border-color); --btn-group-bg-hover: #007bff; --btn-group-text-hover: #ffffff; --btn-group-focus-outline: #007bff; } .btn-group-container-1 { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; display: flex; justify-content: center; align-items: center; padding: 2rem; background-color: #f8f9fa; } .btn-group-1 { display: inline-flex; border-radius: 8px; /* The container has the radius */ overflow: hidden; /* This helps with border-radius on children */ } .btn-group-1 button { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; padding: 0.8rem 1.5rem; font-size: 1rem; font-weight: 600; line-height: 1.5; color: var(--btn-group-text-color); background-color: var(--btn-group-bg); border: 1px solid var(--btn-group-border-color); border-radius: 0; /* Individual buttons have no radius initially */ cursor: pointer; transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out; } /* --- Joining Logic --- */ /* All but the first child have their left border removed via negative margin */ .btn-group-1 button:not(:first-child) { margin-left: -1px; } /* All but the last child */ .btn-group-1 button:not(:last-child) { border-right-width: 1px; } /* Apply border-radius to the first and last buttons in the group */ .btn-group-1 button:first-child { border-top-left-radius: 8px; border-bottom-left-radius: 8px; } .btn-group-1 button:last-child { border-top-right-radius: 8px; border-bottom-right-radius: 8px; } /* --- Interaction States --- */ .btn-group-1 button:hover { background-color: var(--btn-group-bg-hover); color: var(--btn-group-text-hover); z-index: 2; /* Bring the hovered button to the front */ } .btn-group-1 button:focus-visible { outline: 2px solid var(--btn-group-focus-outline); outline-offset: 2px; z-index: 3; } .btn-group-1 button svg { width: 18px; height: 18px; fill: currentColor; } </style> </head> <body> <div class="btn-group-container-1"> <!-- The role='group' and aria-label are essential for accessibility --> <div class="btn-group-1" role="group" aria-label="Text Alignment"> <button type="button" aria-label="Align left"> <svg viewBox="0 0 24 24"><path d="M15 15H3v2h12v-2zm0-8H3v2h12V7zM3 13h18v-2H3v2zm0 8h18v-2H3v2zM3 3v2h18V3H3z"/></svg> </button> <button type="button" aria-label="Align center"> <svg viewBox="0 0 24 24"><path d="M7 15v2h10v-2H7zm-4 6h18v-2H3v2zm0-8h18v-2H3v2zm4-6v2h10V7H7zM3 3v2h18V3H3z"/></svg> </button> <button type="button" aria-label="Align right"> <svg viewBox="0 0 24 24"><path d="M3 21h18v-2H3v2zm6-4h12v-2H9v2zm-6-4h18v-2H3v2zm6-4h12V7H9v2zM3 3v2h18V3H3z"/></svg> </button> </div> </div> </body> </html>