views:

428

answers:

2

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

A: 

I'd suggest using conditional comments: (Put this in the head)

<!--[if lt IE 8]>
        <link href="IE.css" rel="Stylesheet" type="text/css"/>

    <![endif]-->

and setting up some separate CSS_

     input.contact_form_input{
        width:474px;
        height:36px;
        margin:0px;
        margin-bottom:9px;
    margin-left:-10px;/*or whatever px distance works*/
        padding:0px;
        float:left;
/*remove clear:left;*/
    }

That's what I always do to make IE behave.

Kyle Sevenoaks
+3  A: 

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.

Phil.Wheeler
yeah...this is how i used to write me forms...but now i tried to simplify it a bit
kmunky
+1 for proper coding. It's good to simplify codes when it's needed, but these block elements are there for a reason. Phil is right, this would solve your issues :)
Kyle Sevenoaks
first option didn't solve my problem, i decided to wrap my label and input into a <p> and that solved it. let's see if someone can give a pointed answer to my question(maybe is something about ie box model?!) if not i'll mark this answer as correct. thanks @Phil.Wheeler(you encouraged me not to change my old practice :P )
kmunky