Results 1 to 6 of 6

Thread: Form css

  1. #1
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default Form css

    I have made a pretty basic form


    HTML Code:
    <form method="post" action="contact.php">
    <label for="name">Name:</label><input type="text" name="name" maxlenght="20"><br />
    <label for="title">Title:</label><input type="text" name="title" maxlenght="20"><br /><br />
    <label for="content">Message:</label> <br />
    <textarea name="content" cols="40" rows="7"></textarea> <br />
    <input type="submit" name="submit" value="submit">
    </form>
    and am using this css

    HTML Code:
    label
    {
    width: 3em;
    float: left;
    text-align: right;
    margin-right: 0.1em;
    display: block
    }
    
    .submit input
    {
    margin-left: 4.5em;
    }
    It alligns the name and title but not the content box. I would like it to have them all lined up nicely. Any help?
    Last edited by keyboard; 09-04-2011 at 11:26 PM.

  2. #2
    Join Date
    Aug 2011
    Location
    France
    Posts
    7
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Hi,
    A good solution to manage your form layout is to make a class, for instance "myform" that way :

    HTML Code:
    <form class="myform" method="post" action="contact.php">
    css : /*change those values according to your needs*/
    Code:
    .myform 
    {
    	float: left; 
    	clear: both;
    }
    
    .myform label 
    {
    width: 3em;
    float: left;
    text-align: right;
    margin-right: 0.1em;
    display: block
    }
    
    .myform input {
    	width: 12em;
    	margin-left: 1em;
    	margin-bottom: 20px;
    }
    
    .myform textarea {
    	width: 12em;
    	margin-left: 1em;
    	margin-bottom: 20px;
    }
    have fun !

  3. The Following User Says Thank You to david_deseine For This Useful Post:

    keyboard (09-06-2011)

  4. #3
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Thanks for your help. One more thing. How can I allign the submit button with the inputs.

    HTML Code:
    .myform 
    {
    	float: left; 
    	clear: both;
    }
    
    .myform label 
    {
    width: 6em;
    float: left;
    text-align: right;
    margin-right: 0.1em;
    display: block
    }
    
    .myform input {
    	width: 12em;
    	margin-left: 1em;
    	margin-bottom: 20px;
    }
    
    .myform textarea {
    	width: 15em;
    	margin-left: 6em;
    	margin-bottom: 20px;
    }

  5. #4
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default

    where do you want to align them?

  6. #5
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    The textbox and inputs are already alligned. I want to have the submit button the same distance from the left of the screen as the other inputs.

  7. #6
    Join Date
    Aug 2011
    Location
    France
    Posts
    7
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    you have to add a class tou your submit button that way
    HTML Code:
    <input class="mybutton" type="submit" name="submit" value="submit">
    then add in css this for example :

    Code:
    .myform input.mybutton {
    	width: 3em;
    	margin-left: 1em;
    	
    	
    }

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •