This can be achieved neatly with the following snippet, which sets the opacity of input to 0 (invisible) and sets the background of the parent div to the selected color.
$(document).ready(function() {
$('#color1').on('input', function() {
$(this).parent().css({
background: $(this).val()
});
});
});
#color1 {
border: none;
opacity: 0;
}
.rounded {
display: inline-block;
border-radius: 10px;
background: black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="rounded">
<input type="color" id="color1" />
</div>
jQuery is being used for changing the background of the parent to the selected color - credits goes to this answer for the 'input' event handler.
Having that said, if you also want a second color as in your snippet, just put another div as parent of .rounded
and set the color to your preference.
$(document).ready(function() {
$('#color1').on('input', function() {
$(this).parent().css({
background: $(this).val()
});
});
});
#color1 {
border: none;
opacity: 0;
}
.rounded,
.wrapper {
display: inline-block;
border-radius: 10px;
}
.rounded {
background: black;
}
.wrapper {
padding: 10px;
background: lightgray;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<div class="rounded">
<input type="color" id="color1" />
</div>
</div>
This snippet will work in all the modern browsers versions, including IE 10. See the CanIUse page for more information on compatibility.