Friday, September 25, 2009

IE6 Bug: Relative Box After Float Doesn't Show

Consider the following code where you have a floated element (in this case a label), followed by a div with position: relative, containing an input field with a width: 100%.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="" xml:lang="en" lang="en">
<style type="text/css">
.label { float: left; }
.div { position: relative; }
.input { width: 100%; }
<label class="label">Label</label>
<div class="div">
<input class="input" type="text"/>
The issue is that on IE6, the input field doesn't show:

This bug has been resolved in IE7, and you can easily work around it in IE6 by forcing the box to "have layout" (in IE, elements with position: absolute have layout, but elements with position: relative don't necessarily have layout). My favorite way for doing so it to add a *zoom: 1 on the box, which will give you the expected result: