输入类型的颜色样式 [英] Input type color styling
问题描述
我有一个小问题,因为我不太擅长CSS,所以我想知道是否有什么方法可以重新创建这种出色的input [type = color]元素样式?我的意思不是屏幕快照上的所有内容,而是输入[type = color]的那个漂亮圆圈。
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 the screenshot but only that pretty circle which is input[type=color].
在这里,我用它编写了一些代码,但是它没有像截图那样对输入[type = color]进行样式设置。此外,我还看到作者使用了Vue。 js在他的项目中...非常感谢您的帮助!
Here I have some code that was written with it but it's not styling the input[type=color] like on a screenshot... Also I have seen that the author uses Vue.js in his project... Thank you very much for help!
<input type="color" id="primary_color" class="field-radio" name="primary-color" v-model="scheme.primary" @change="changeColor()">
input[type="color"] {
width: 3rem;
height: 3rem;
padding: .5rem;
background-color: transparent;
border: 0;
border-radius: 100%;
}
input[type="color" i] {
-webkit-appearance: square-button;
width: 44px;
height: 23px;
background-color: buttonface;
cursor: default;
border-width: 1px;
border-style: solid;
border-color: rgb(169, 169, 169);
border-image: initial;
padding: 1px 2px;
}
input {
-webkit-appearance: textfield;
background-color: white;
-webkit-rtl-ordering: logical;
cursor: text;
padding: 1px;
border-width: 2px;
border-style: inset;
border-color: initial;
border-image: initial;
}
input, textarea, select, button {
text-rendering: auto;
color: initial;
letter-spacing: normal;
word-spacing: normal;
text-transform: none;
text-indent: 0px;
text-shadow: none;
display: inline-block;
text-align: start;
margin: 0em;
font: 400 13.3333px Arial;
}
input, textarea, select, button, meter, progress {
-webkit-writing-mode: horizontal-tb;
}
推荐答案
这是您需要的代码:
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%;
}
<div class="container">
<input type="color" id="primary_color" class="field-radio">
<span class="container" id="color_val"></span>
</div>
容易理解,
祝您好运! :)
Easy enough to understand, Good luck! :)
这篇关于输入类型的颜色样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!