Need help with css form layout being inconsistent

Hey all,

I’m helping a friend of the family set up a GP website for their business.
Part of the idea is to help people order their regular medicine online rather than always calling or making appointments.

I have put together a few rough things for now until I get it all working.

I have a basic layout here for the order form, but when I viewed it on their machine (IE7 I think), the form was all down one side and looked awful!

You can get this by switching compatibility mode on and off in IE.

The form is here:
http://mgdesign.hostultra.com/GP_Edit/repeat_prescriptions.html

I’ve made a real mess of my code in parts, my eyes hurt and i dont know what I have done wrong :confused:

Here is some of the css i did for the form layout:


/* ----------------- ORDER FORM ------------------- */

#form_left

{
	margin:0px 0px 0px 0px;
	width:290px;
	margin-top:0px;
	float:left;
	}


#form_right

{
	margin:0px 0px 0px 0px;
	width:550px;
	margin-top:0px;
	}


#form_left2

{
	margin:0px 0px 0px 0px;
	width:290px;
	margin-top:10px;
	float:left;
	}


#form_left3

{
	margin:0px 0px 0px 0px;
	width:400px;
	margin-top:10px;
	float:left;
	}

#form_right2

{
	margin:0px 0px 0px 0px;
	width:550px;
	margin-top:0px;
	}


Here is my code for the form:

<h3>Order Form</h3>


<form method="post" action="mailer.php">
    <div id="form_left">
         
              Your Name:<br /><br />
   <input type="text" name="name" size="24" /><br />
  
   <br />
   <br />
   
    Your Email:<br /><br />
   <input type="text" name="email" size="24" />
 
 </div>
 
 <div id="form_right">
Your Date of Birth:<br /><br />
  <input type="text" name="dob" size="24" /><br />
  <br />
  
  </div>


    <div id="form_left2"><br /><br />
 National Insurance Number:<br /><br />
  <input type="text" name="nin" size="24" /><br />
    <br /><br />
  
  </div>
  
  <br />
  

    <div id="form_right2">
    
   Prescription Pickup Point:<br /><br />
   
    <select name="pickup">
    <option>Ballymena GP Practice</option>
    <option>Boots</option>
    <option>Another Option</option>
    <option>Another Option 2</option>
	</select>
   

</div>

    
    <div id="form_left3">

   <p>Please specify the details of your order, including name &amp; quantity :</p>
   <textarea rows="10" name="message" cols="55" /></textarea>
   <br />
       
         <p>Please ensure that you have filled out all important information before submitting.</p>
         
         <p><b>You must provide photographic ID when picking up your order.</b></p>

 <br />
 
    <input type="submit" value="Submit" name="submit" />
	
 </form>
    
 <h4>Prescription Security</h4>
 
 <p>Please note....</p>
 

If anyone can help me with what I can do to get this consistent I would be much obliged!!

Thanks:)

Yes that’s better.:slight_smile:

You could still get rid of the breaks by setting the label and the input to display:block in that section and apply margins to the parent div to move each further away (or even margins on the label or input).

However forms are one of the few places where a break can be used to make a line break between elements but in most other scenarios breaks should be avoided when used to just to make space and there is never a time when two breaks next to each other are a good idea.

You would use breaks between the lines of a poem or between the lines in an address. In most other cases a break is nt needed as you can use the margins on the exiting element to control the spacing more accurately.

Paul -

Please ignore that last post I am a bit off the pace today.

Right so this is the adjustments I have made. It runs much better now thanks to your help!!

I deleted those unnecessary ID coding and replaced them with classes and two IDs.

Your comments are very welcome on this.

<snip/> Link in OP

<form method="post" action="mailer.php">
   
<div id="level">
    	
        <div class="form_left">
         
   		<label for="name">Your Name</label><br />
   		<input type="text" name="name" size="24" /><br />
   		</div>
   
   
  		 <div class="form_right">
     	<label for="email">Your Email</label><br />
   		<input type="text" name="email" size="24" />
  		</div>
        
        
</div>
 
 
 
 
<div id="level2">
 
     <div class="form_left">
     <label for="name">Your Date of Birth</label><br />
      <input type="text" name="dob" size="24" />
      </div>


      <div class="form_right">
      <label for="nin">National Insurance Number</label><br />
      <input type="text" name="nin" size="24" /><br />  
      </div>
  

</div>
  

    <div class="form_left">
    
  	<label for="pickup">Prescription Pickup Point</label><br />
   
    <select name="pickup">
    <option>K1 Boots Cushendall Road</option>
    <option>K2 Boots Tower Centre</option>
    <option>K3 Sainsburys</option>
    <option>K4 Dunclug</option>
    <option>K5 Lloyds</option>
    <option>K6 Boots Harryville</option>
    <option>K7 Woodsides</option>
    <option>K8 Broughshane</option>
    <option>K9 Kells</option>
    <option>K10 Simpsons Galgorm</option>
    <option>K11 Ahoghill</option>
    <option>K12 Boots Cullybackey</option>
    <option>K13 Ballykell</option>
    <option>K14 Ballee</option>
	</select>
   

</div>

<br /><br /><br /><br />
  
   <label for="message">Please specify the details of your order, including name &amp; quantity</label> 
   <textarea rows="10" name="message" cols="55"></textarea>
   <br />
      
      
         <p>Please ensure that you have filled out all important information before submitting.</p>
         <p><b>You must provide photographic ID when picking up your order.</b></p>

 <br />
 
    <input type="submit" value="Submit" name="submit" />
	</form>

.form_left
{
margin:0px 0px 0px 0px;
width:260px;
float:left;
}

.form_right

{
	margin:0px 0px 0px 0px;
	float:right;
	width:260px;
	}


#level
{
	width:580px;
	height:50px;
	clear:both;
	margin-bottom:15px;
}


#level2
{
	width:580px;
	height:50px;
	margin-bottom:15px;
	clear:both;
}

Thanks for your input Paul, much appreciated!

If I was to write a form_right class in my CSS would that eliminate the need for the IDs for form_left, right etc?

would this be a correct replacement in my css:

#form_left

{
margin:0px 0px 0px 0px;
width:290px;
margin-top:0px;
float:left;
}

to become:

.form_left
{
margin:0px 0px 0px 0px;
width:290px;
float:left;
}

Ideally I would like to not rely on the IDs and use classes for simplicity and cleaner code.

Hi,

The problem in IE7 is that you have set a width to the form-right elements which means that there is no room for the form_left element ans so it starts on a new line and clears the form_left element.

Remove the widths.

e.g.


#form_left {
    margin:0px 0px 0px 0px;
    width:290px;
    margin-top:0px;
    float:left;
}
#form_right {
    margin:0px 0px 0px 0px;
 [B]   /*width:550px;*/[/B]
    margin-top:0px;
}
#form_left2 {
    margin:0px 0px 0px 0px;
    width:290px;
    margin-top:10px;
    float:left;
}
#form_left3 {
    margin:0px 0px 0px 0px;
    width:400px;
    margin-top:10px;
    float:left;
}
#form_right2 {
    margin:0px 0px 0px 0px;
[B]    /*width:550px;*/[/B]
    margin-top:0px;
}

In reality it is always better to float both items when you want two columns and avoid all the IE bugs (apart from the double margin bug on floats which can be killed by adding display:inline). Then just make sure that each pair of left and right floats is wrapped in a div that is set to clear:both so that each pair starts level.

Regarding your layout you should not use breaks to make space but use margins on the elements themselves.

The form labels should be in label elements anyway which gives you automatic hooks for styling and positioning at the same time as being semantic.

e.g.This:


<div id="form_right"> Your Date of Birth:<br />
                <br />
                <input type="text" name="dob" size="24" />
                <br />
                <br />
            </div>

should be something like this:


<div class="form_right">
    <label for="dob">Your Date of Birth:</label>
    <input type="text" name="dob" id="dob" size="24" />
</div>


Don’t use numerous ids when the styling is the same. Just use the same class. In a lot of cases multiple classes can be avoided by targeting via context instead using a parent id.

I notice you have html comments in your css file which is not allowed and may trip some browsers up. Only css and css comments are allowed in external css files.

I really cant get this to validate, can someone help please?

Its something to do with where the form is being closed off at and an end div.

Totally stumped!

Trying to validate:
<snip/> Link in OP

I’ve made a real mess of my code in parts, my eyes hurt and i dont know what I have done wrong :confused:

Let’s start with:

http://validator.w3.org/check?verbose=1&uri=http%3A%2F%2Fmgdesign.hostultra.com%2FGP_Edit%2Frepeat_prescriptions.html

and:

http://jigsaw.w3.org/css-validator/validator?profile=css2&warning=2&uri=http%3A%2F%2Fmgdesign.hostultra.com%2FGP_Edit%2Frepeat_prescriptions.html

Then we can work on your float drop.