Extended button hit box
by Patrick Rudolph
HTML
<button>
<div class="innerButton">Click me!</div>
</button>
CSS
* {
margin: 0;
padding: 0;
border: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html {
background-color: #eee;
-webkit-tap-highlight-color: rgba(0,0,0,0);
-webkit-tap-highlight-color: transparent;
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
button {
margin: 10px;
padding: 10px;
background: #e4e4e4; /* change to 'transparent' for invisible touch targets */
outline: 0;
cursor: pointer;
}
.innerButton {
padding: 5px 10px;
background: #ccc;
border-radius: 5px;
}
button:hover .innerButton {
background: #aaa;
}
button:active .innerButton {
background: orange;
}
JavaScript
document.querySelector('button').addEventListener('click', function() {
alert('clicked!');
});