Results 1 to 8 of 8

Thread: submit button in html and css

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2011
    Posts
    55

    submit button in html and css

    hi all,
    i have created one simple login form using html an css.in that login form how to change the position of the submit button to center, right and left.
    presently it is left now....
    where to change the position......
    below is my html code..
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Dynamic Inline Form Validation Demo</title>
    <link rel="stylesheet" type="text/css" href="messages1.css" />
    <script type="text/javascript" src="messages1.js"></script>
    </head>
    <body>
    <div id="wrapper">
      <form name="form" id="form" class="form" action="success1.html" onsubmit="return validate(this)" method="post">
        <label for="name">User Name:</label>
        <input type="text" name="realname" id="name" />
    	<span id="realnameerror"></span>
        
    	<label for="email">Email Id:</label>
        <input type="text" name="email" id="email" />
    	<span id="emailerror"></span>
        
    	<label for="password">Password:</label>
        <input type="password" name="password" id="password" />
    	<span id="passworderror"></span>
    	
        <label for="repassword">Retype Password:</label>
        <input type="password" name="password2" id="password2" />
    	<span id="password2error"></span>
    	
    	<label for="phoneno">Phone no:</label>
        <input type="text" name="phoneno" id="phoneno" />
    	<span id="phonenoerror"></span>
    	
    	<input type="submit" value="Submit" class="submit" />
      </form>
    </div>
    </body>
    </html>
    below is the css for it.....
    Code:
    * 
    {
     margin:0; 
     padding:0;
    }
    
    body 
    {
      font:12px Verdana, Arial, Helvetica, sans-serif; 
      color:black;
    }
    
    #wrapper 
    {
      width:700px; 
      margin:50px auto;
    }
    
    .form 
    {
      float:left; 
      padding:10px 10px 10px 10px; 
      background:lightblue; 
      border:2px solid white;
    }
    
    .form label 
    {
      float:left; 
      width:130px; 
      padding:10px 10px 0 0; 
      font-weight:bold;
      text-align:right;
      clear:left;
    }
    
    .form span
    {
      float:left;
      margin-top:1em;
      margin-left:0.5em;
      color:red;
    }
    
    .form select 
    {
      float:left; 
      width:146px; 
      margin-top:10px;
    }
    
    .form input 
    {
      float:left; 
      margin-top:10px;
    }
    
    .form .submit 
    {
      clear:both;
    }
    
     #msg 
    {
      display:none; 
      position:absolute; 
      z-index:200; 
      background:url(images/msg_arrow.gif) left center no-repeat; 
      padding-left:7px;
    }
    #msgcontent 
    {
      display:block; 
      background:yellow; 
      border:2px solid orange; 
      border-left:none; 
      padding:5px; 
      min-width:150px; 
      max-width:250px;
    }

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: submit button in html and css

    create a submit class in your CSS and set the align to center...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Lively Member
    Join Date
    Jul 2011
    Posts
    127

    Re: submit button in html and css

    try this one.
    Code:
    <center><input type="submit" value="Submit" class="submit" /></center>

  4. #4
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: submit button in html and css

    Quote Originally Posted by rj_yan31 View Post
    try this one.
    Code:
    <center><input type="submit" value="Submit" class="submit" /></center>
    A better way would be to leave out the <center></center> tags and use either the name or class attribute to move the button via code in the css file.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  5. #5
    Member PBertie's Avatar
    Join Date
    Aug 2011
    Location
    Newcastle Upon Tyne
    Posts
    55

    Re: submit button in html and css

    Can I ask why you are using float in your CSS?
    Float is not a normal way to align things, its special because it allows elements to overlap. Like a picture in a column of text in a book.

    If you want to keep the floats on your other elements you will need to change your submit class to the following because the .form input {} also effects the submit button.

    Code:
    .form .submit 
    {
      float:none;
      margin-left: auto;
      margin-right: auto;
    }

    Also <center> is deprecated so should be avoided.

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: submit button in html and css

    Instead of adding a class, use an attribute selector:
    Code:
    .input[type='submit']
    {
      margin: 0 auto;
    }
    I don't know off-hand if the margin trick works on a submit button.

  7. #7
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: submit button in html and css

    It doesn't, as far as I recall (even when given an explicit width).

    To center a submit button, I always just apply text-align to its parent element. Something like:
    HTML Code:
    <div class="submit">
      <input type="submit" value="Go" />
    </div>
    Code:
    .submit {
      text-align: center;
    }
    Like Archer? Check out some Sterling Archer quotes.

  8. #8
    Fanatic Member
    Join Date
    May 2004
    Location
    Quetta-Pakistan
    Posts
    852

    Re: submit button in html and css

    Create a DIV and use its Top/Bottom/Left properties to align the button

Posting Permissions

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



Click Here to Expand Forum to Full Width