Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What causes the horizontal scrollbar to appear on Chrome in the following most trivial HTML?

HTML:

<html>

  <body>
    <div>
      <input type="text">
    </div>
  </body>

</html>

CSS:

 body {
   font:13px/1.231 arial;
 }
 input {
   font:99% arial;
 }
 div {
   display: inline-block;
   overflow: auto;
 }
 input {
   width: 15em;
 }

The result on Chrome:

enter image description here

The jsFiddle - http://jsfiddle.net/XBvWb/18/

Note that neither FF nor IE9 show this scrollbar.

Can anyone enlighten me, please, what is going on?

EDIT

Removed the input border, padding and margin - http://jsfiddle.net/XBvWb/41/

like image 720
mark Avatar asked Jan 06 '13 20:01

mark


1 Answers

My guess is that Chrome has a problem with rounding.

If you use any value of px for the inputs width the scrollbar disappears. Same when you change the inputs font-size to 100% (which equals exactly 13px in this example).

The current width of the input is 15 * 99% * 13px = 193.05px

I think the .05px let the scrollbar appear.

That also clarifies why the scrollbar disappears for widths of around 11em. It just rounds up in manner Chrome can handle better.

like image 82
dave Avatar answered Nov 15 '22 19:11

dave