Aligning form elemnts in a div

Discussion in 'CSS' started by RexRon, Jul 28, 2010.

  1. #1
    Hello.

    I have finally gotten around to replace tables with CSS. A few bumps in the road are therefore to be expected.
    The image below is quite self explanitory. I want the text field and the button to line up.
    [​IMG]

    Here´s the CSS for the div in question:
    #SearchBox {
       position: relativ;
       width: 293px;
       height: 48px;
       margin-left: 0px;
       margin-top: 15px;
       font-weight: normal;
       padding-left:0px;
       padding-right:0px;
    }
    Code (markup):
    And here´s the div itselfe:
    <DIV id="SearchBox" class="alignCenter">
    <form method="GET" action="search_results.php">
    <input type="text" name="zoom_query" size="25">
    <input type="image" src="images/searchbutton.jpg">
    </form></DIV>
    
    Code (markup):
    Can anyone tell me whats missing please?

    Sincerely
    Ronny
     
    RexRon, Jul 28, 2010 IP
  2. Zeh.

    Zeh. Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try with #SearchBox input[type="image"] { margin-top: something; } till you get what you want.

    Getting inputs heights and aligns right and crossbrowser is a headache.
     
    Zeh., Jul 28, 2010 IP
  3. radiant_luv

    radiant_luv Peon

    Messages:
    1,327
    Likes Received:
    34
    Best Answers:
    1
    Trophy Points:
    0
    #3
    Both the inputs can be float to left with relatively positioned in the respective style element.

    For example:
    Markup
    
    <DIV id="SearchBox" class="alignCenter">
    <form method="GET" action="search_results.php">
    <input[B] id="searchfield"[/B] type="text" name="zoom_query" size="25">
    <input [B]id="searchbutton" [/B]type="image" src="images/searchbutton.jpg">
    </form></DIV>
    
    Code (markup):
    Style
    
    #searchfield{
    position:relative;
    float:left;
    margin:0px;
    }
    #searchbutton{
    position:relative;
    float:left;
    margin:0px;}
    }
    
    Code (markup):
    Hope this should resolve the issue, else a live link to view the page would be great.

    I am afraid, playing around with the margin for the image (button) may give you inconsistent results on cross-browsers.
     
    radiant_luv, Jul 28, 2010 IP
  4. RexRon

    RexRon Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hello and thanks for your reply.

    What you sugested aligns the field and button as long as the float parameter is "left". When trying to center it the same problem happens again. I suppose I could give a margin-left:10px or something but the problem doesn´t end there :) As the pic above shows I´d like for the searchfield to be in a box of 63px in height so it corresponds with the background.

    Am I making any sence?

    Here´s a link: www.secondparadigm.eterya.com/indexcss.php

    Can´t post a link properly until I´ve been a member for seven days...
     
    RexRon, Jul 29, 2010 IP
  5. RexRon

    RexRon Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for the help...
    I found away around it using margin-left, top and bottom parameters in the style sheet.

    At least it looks good from my end now :)
     
    RexRon, Jul 29, 2010 IP