Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change an inputs border colour without changing the style?

Tags:

html

css

I'm trying to do something pretty simply; change the border colour of an input. In both IE11 and latest stable Chrome, changing the color also changes how it looks (appears 3D/thicker):

Wonkey CSS Borders

If I try "1px solid red" then the border looks the same, but the size changes!

  1. Why does changing the colour seem to do more than just change the colour
  2. How can I just change the colour without changing anything else (style, thickness, spacing, size, etc.)

I've tried messing with border-width and other properties, but none of them result in the exact same size/spacing as the default with only the colour changed :(

(Please try your changes in JSFiddle before posting... so many people are posting bad answers and then deleting them! http://jsfiddle.net/S2TxT/4/)

<input type="text" value="Default" />
<input type="text" style="border: 1px solid red" />
like image 262
Danny Tuppeny Avatar asked Dec 18 '13 10:12

Danny Tuppeny


2 Answers

In IE11 and Chrome, this got me matching boxes.

As for why... browsers will be browsers?

<input type="text" value="Default" />
<input type="text" value="Default" style="padding: 2px 1px; border: 1px solid red" />

http://jsfiddle.net/S2TxT/11/

EDIT

After further investigation, it becomes apparent why this might happen: http://jsfiddle.net/S2TxT/18/

like image 184
LiverpoolsNumber9 Avatar answered Sep 30 '22 08:09

LiverpoolsNumber9


This is the simplest way I can find of fixing the problem. Unfortunately, it involves changing the height CSS. Crazy, I know, just for a border color change!

<input type="text" value="Default" />
<input type="text" style="border: 1px #cecece solid; padding: 2px; height: 16px;" />

http://jsfiddle.net/S2TxT/10/

like image 33
Qboid Avatar answered Sep 30 '22 06:09

Qboid