Skip to content

Instantly share code, notes, and snippets.

@maxcraftsman
Last active April 16, 2018 01:14
Show Gist options
  • Save maxcraftsman/246efd7ba2c0e2085f960a69faa1682c to your computer and use it in GitHub Desktop.
Save maxcraftsman/246efd7ba2c0e2085f960a69faa1682c to your computer and use it in GitHub Desktop.
Input number with plus/minus buttons [html,sass]
<div class="number-input">
<button type="button" onclick="this.parentNode.querySelector('input[type=number]').stepDown()"></button>
<input class="quantity" min="0" name="quantity" value="1" type="number">
<button type="button" onclick="this.parentNode.querySelector('input[type=number]').stepUp()" class="plus"></button>
</div>
<style>
.number-input {
display: inline-flex;
width: 80px;
height: 30px;
background-color: #f9f9f9;
&, & * {
box-sizing: border-box;
}
& input[type="number"] {
-webkit-appearance: textfield;
-moz-appearance: textfield;
appearance: textfield;
border: 0px;
padding: 0;
box-shadow: none !important;
font-family: sans-serif;
font-size: 14px;
width: 30px;
height: 100%;
text-align: center;
color: #777777;
background-color: #f9f9f9;
}
& input[type=number]::-webkit-inner-spin-button,
& input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
}
& button {
position: relative;
outline:none;
-webkit-appearance: none;
background-color: transparent;
border: none;
align-items: center;
justify-content: center;
width: 30px;
height: 100%;
cursor: pointer;
margin: 0;
font-family: "Helvetica";
font-size: 16px;
color: #999999;
font-weight: normal;
position: relative;
&:hover:after {
background-color: #eee;
}
&:after {
display: inline-flex;
position: absolute;
justify-content: center;
align-items: center;
top: 0px;
left: 0;
right: 0;
width: 100%;
height: 100%;
bottom: 0px;
margin: auto;
content: '−';
}
&.plus:after {
content: '+';
}
}
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment