Here is an example, this demo shows that text line is at wrong position. Why?
demo: https://codepen.io/ahuigo/pen/yLQjxew?editors=1010
<div class="main">
<b style="border: 1px solid;">text line</b>
<input type="color" value="#0000ff">
</div>
<style>
.main{
border: 1px solid red;
box-sizing: border-box;
}
input{
height: 22px;
}
input[type="color"] {
-webkit-appearance: none;
appearance: none;
border: none;
padding: 0;
border-radius: 2px;
}
input[type="color"]::-webkit-color-swatch-wrapper {
padding: 0;
margin: 0;
}
</style>
2
Answers
It’s the
padding: 0
on the color input, not the fact that it’s a color input. You can fix it by makingmain
a flex container, or using one of the other methods on How to center in CSS.Also,
// foo
isn’t a comment in CSS, you have to use/* foo */
.I am not sure if I understood your problem correctly but do you search for this solution?
make a parent div to put both in a
flexbox
. Withgap
you can set the spacing between the text and the input, would be cleaner than using margin-left or something like that…Btw to get the input
border-radius
working you need to setoverflow: hidden
.Hope it helps! 🙂
And yes,
// foo
isn’t a comment in CSS, you have to use/* foo */
. (Credits Zac Anger)