width:auto for <input> fields

Posted by richb on Stack Overflow See other posts from Stack Overflow or by richb
Published on 2011-01-07T02:46:14Z Indexed on 2011/01/07 2:54 UTC
Read the original article Hit count: 135

Filed under:

Newbie CSS question. I thought 'width:auto' for a display:block element meant 'fill available space'. However for an <input> element this doesn't seem to be the case. For example:

<body>
<form style='background-color:red'>
<input type='text' style='background-color:green;display:block;width:auto'>
</form>
</body>

Two questions then:

  1. Is there a definition of exactly what width:auto does mean? The CSS spec seems vague to me, but maybe I missed the relevant section.

  2. Is there a way to achieve my expected behaviour for a input field - ie. fill available space like other block level elements do?

Thanks!

© Stack Overflow or respective owner

Related posts about css