Is there a Webkit-specific CSS style that will allow me to control the color/size/style of the box around the color in an input[type=color]
? I'm setting the color and background color of the input already so it looks good with a cross-compatibility polyfill I'm using for older Chrome and Firefox. But now that Chrome actually has a color picker, there's a box around the color which leaves a 1px grey box floating in the middle of the input when both color and background color of the input are set to the same color. Is there some CSS to get rid of it, either by setting that box's width to 0, changing the style to none
, or, at worst, setting the color to the same as the color and background color?
In this image, I'm talking about the grey box inside the white and outside the green:
I've found one workaround, which is to set a high enough padding that the box (the grey border and green contents) is squished to size 0. But that's really hacky, and doesn't look very good over in Firefox.
My method:
And it view like this: http://prntscr.com/gloozc
But if you press Ctl+F5, you`ll see original input for a moment.
WebKit has special CSS selectors you can use to customize form controls but they aren't official.
An update to WebKit in the future will probably break it.
Please don't use it for production!!
But feel free to play with it for personal projects :)
Method 1
Uses webkit-specific selectors to mostly hide the non-colored part of the input.
Method 2
Hides the color input (
opacity:0
) and uses JavaScript to set the background of the wrapper to the input's value.a good workaround is to:
1.wrap your color picker in a label. 2.set the color picker's visibility to false. 3.bind the label's background color to the value of the color picker.
now, you have an easy to style label that when clicked, opens your color picker :
JSFiddle
This is how I did it for a art project recently. I am a newbie, so let me know if I did this horribly wrong.
I am using a simple solution, but not so elegant, I guess. You can wrap the input with a div and make the input bigger than the container, after that you can shape the container as you want. You can also use a label with a for attribute to create a clickable button with some text.
I have made an example:
Unfortunately, color inputs are quite finicky. Different browsers treat them differently. For example, Chrome will size the input based on
width
/height
+border-width
. Firefox, on the other hand, will use the maximum ofwidth
/height
andborder-width
. This makes equal spacing quite difficult, with<input type=color>
by itself.However, what we can do is remove everything except for the picked color itself, and throw a wrapper around it that will be able to more predictably handle the spacing around the input.