Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does input[type="text"] change size on focus?

Tags:

html

css

input

Say I have an input.

html

<input type="text">

css:

input, input:focus {
  border: none;
  outline: solid 1px grey;
  box-shadow: none;
}

When clicked, the input changes size. How do I stop this?

http://codepen.io/mildrenben/pen/QwVvZK

like image 737
mildrenben Avatar asked Mar 07 '15 18:03

mildrenben


1 Answers

If you're looking in Chrome, it's because of the following default user-agent styling:

input:focus, textarea:focus,
keygen:focus, select:focus {
    outline-offset: -2px;
}

Therefore you need to set the outline-offset to 0 when focusing on the element:

Updated Example

input:focus {
  outline-offset: 0;
}
like image 93
Josh Crozier Avatar answered Sep 19 '22 20:09

Josh Crozier