Input type color styling

后端 未结 4 1994
梦谈多话
梦谈多话 2021-02-14 06:33

I have a small question, since I\'m not too good at CSS i want to know if there any way I can recreate such a nice input[type=color] element\'s style? I mean not everything on t

4条回答
  •  忘了有多久
    2021-02-14 06:48

    Here is the code you need:

    var colorButton = document.getElementById("primary_color");
        var colorDiv = document.getElementById("color_val");
        colorButton.onchange = function() {
            colorDiv.innerHTML = colorButton.value;
            colorDiv.style.color = colorButton.value;
        }
    #primary_color{
        border-radius: 100%;
        height: 60px;
        width: 60px;
        border: none;
        outline: none;
        -webkit-appearance: none;
    }
    
    #primary_color::-webkit-color-swatch-wrapper {
        padding: 0;	
    }
    #primary_color::-webkit-color-swatch {
        border: none;
        border-radius: 100%;
    }

    Easy enough to understand, Good luck! :)

提交回复
热议问题