Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does border css shrink width in firefox

i have this css to highlight input when they are in focus:

input:focus, textarea:focus{  
  background-color: #FFFF99;  
  border-width: 1px;  
  border-style:solid;  
  border-color:Black;  
}

i just noticed that when i click on a textbox it shrinks by a very small but noticable amount. Is there any reason why the css above would change the width & height of a textbox when i have it in focus?

i am using firefox 3.16

like image 355
leora Avatar asked Apr 11 '26 11:04

leora


1 Answers

it shrinks because the default borders of a textarea input are 2-3px and you're only overriding them to 1px in the focus state

it won't shrink if you override the default borders to be the same width e.g.:

input, textarea {
  border: 1px solid #444;
}

input:focus, textarea:focus{  
 background-color: #FFFF99;  
 border-width: 1px;  
 border-style:solid;  
 border-color:Black;  
 }

Update

to retain original dimensions without recalculating for borders this appears to work:

input, textarea {
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  -ms-box-sizing: border-box;
  box-sizing: border-box;
  width: 300px;
  height: 50px;

}

input:focus, textarea:focus{  
 background-color: #FFFF99;  
 border-width: 1px;  
 border-style:solid;  
 border-color:#000;  
 }
like image 118
clairesuzy Avatar answered Apr 13 '26 02:04

clairesuzy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!