Created
September 28, 2019 06:53
-
-
Save greystate/3bb47e9ce9251ec72c66ecc854df08a6 to your computer and use it in GitHub Desktop.
Andy's breakout button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Andy's breakout button | |
| */ | |
| html { | |
| background: #f06; | |
| background: linear-gradient(45deg, #f06, yellow); | |
| min-height: 100%; | |
| } | |
| body { | |
| padding: 3rem 2rem; | |
| line-height: 1.4; | |
| font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, | |
| sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; | |
| font-size: 1.2rem; | |
| } | |
| h1 { | |
| font-size: 2rem; | |
| line-height: 1.1; | |
| font-weight: 600; | |
| } | |
| .box { | |
| color: #fff; | |
| padding: 2rem; | |
| max-width: 30rem; | |
| background: #252525; | |
| position: relative; | |
| box-shadow: none; | |
| transition: transform 300ms ease-in-out, box-shadow 400ms ease, background 100ms ease; | |
| } | |
| .box:hover, | |
| .box:focus-within { | |
| background: #111111; | |
| box-shadow: 0 1rem 1rem rgba(0, 0, 0, 0.3); | |
| transform: translateY(-0.5rem); | |
| } | |
| .box > * + * { | |
| margin-top: 1em; | |
| } | |
| .breakout-button { | |
| font: inherit; | |
| font-weight: 600; | |
| padding: 0.6rem 2rem; | |
| background: transparent; | |
| color: currentColor; | |
| border: 1px solid; | |
| transition: background 100ms ease; | |
| position: static; | |
| } | |
| .breakout-button, | |
| .breakout-button::before { | |
| cursor: pointer; | |
| } | |
| .breakout-button::before { | |
| content: ''; | |
| display: block; | |
| position: absolute; | |
| top: 0; | |
| left: 0; | |
| width: 100%; | |
| height: 100%; | |
| } | |
| .breakout-button:focus { | |
| outline: none; | |
| } | |
| .breakout-button:hover { | |
| background: #333333; | |
| } | |
| .breakout-button:focus::before { | |
| outline: 1px solid #ffffff; | |
| outline-offset: -0.8rem; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <article class="box"> | |
| <h1>A semantic, breakout button</h1> | |
| <p>This whole box is clickable, but still uses a button element, correctly.</p> | |
| <button hidden class="breakout-button" type="button">Say Hi ๐</button> | |
| </article> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const button = document.querySelector('.breakout-button'); | |
| if (button) { | |
| button.parentElement.setAttribute('data-interactive', ''); | |
| button.removeAttribute('hidden'); | |
| button.addEventListener('click', evt => { | |
| evt.preventDefault(); | |
| alert('Oh hi there ๐'); | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {"view":"separate","fontsize":"100","seethrough":"","prefixfree":"1","page":"result"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment