Search code examples
htmlcssinternet-explorer-7internet-explorer-6

IE7 bug, my form input fields get indented


HTML

<form id="contact_form" action="#" name="" method="POST">
  <label for="name">NAME</label>
  <input type="text" name="name" id="name" class="contact_form_input" />
  <label for="email">EMAIL</label>
  <input type="text" name="email" id="email" class="contact_form_input" />
  <label for="subject">SUBJECT</label>
  <input type="text" name="subject" id="subject" class="contact_form_input" />
  <label for="message">MESSAGE</label>
  <textarea name="message" id="message"></textarea>
  <input type="submit" class="submit" name="submit" value="Submit" />
  <input type="reset" class="reset" name="reset" value="Reset" />
</form>

CSS

form#contact_form{
width:auto;
height:auto;
margin:0px;
margin-left:73px;
padding:0px;
float:left;
clear:both;
}

form#contact_form label{
float:left;
clear:both;
margin-left:3px;
margin-bottom:6px;
font-family:Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size:12px;
font-style:italic;
font-weight:bold;
}

input.contact_form_input{
width:474px;
height:36px;
margin:0px;
margin-bottom:9px;
padding:0px;
float:left;
clear:left;
}

form#contact_form textarea{
width:479px;
height:150px;
margin-bottom:9px;
float:left;
clear:left;
}

you can see here that in IE7 that text inputs gets some kind of "margin-left". How can i get rid of that margin? thanks


Solution

  • Your easiest option would actually be to use the following CSS:

    form#contact_form label{
    display: block;
    margin-left:3px;
    margin-bottom:6px;
    font-family:Verdana, Geneva, Arial, Helvetica, sans-serif;
    font-size:12px;
    font-style:italic;
    font-weight:bold;
    }
    

    But I would recommend you wrap each of your input rows (including the label) in a block-level element such as a <p> tag or a list item:

    <form id="contact_form" action="#" name="" method="POST">
      <ul>
        <li>
          <label for="name">NAME</label>
          <input type="text" name="name" id="name" class="contact_form_input" />
        </li>
      ...
    

    This article from A List Apart is an excellent introduction.