tags:

views:

72

answers:

3

I have a text box and a button, which is described with the HTML/CSS below.

Currently these two elements are appearing with the button slightly lower than the text box. Can somebody please suggest how I can get these two aligned so their middles are on the same horizontal axis? Thanks

update: apparently the outside world can't see this site. I'll post some HTML describing the controls shortly

update 2: This is the code:

<div id="SearchForm">

    <form method="get" action="/search/Tabs">

        <div class="search-box ActionControl">
            <input type="text" value="" name="Search" id="Search">
            <a href="/search/Tabs">Search</a>
        </div>         

        <div id="ContentArea"></div>

    </form>
</div>

#SearchForm .search-box
{
    padding: 25px;
    height: 25px;

    background-color: #F6E9D8;
    border: 1px solid #E7DFD0;
}

#SearchForm .search-box input
{
    width: 425px;
}

#SearchForm .search-box a
{
    background:url("../../Content/images/100/button-M.png") no-repeat scroll 0 0 transparent;
    border:0 none;
    color:White;
    cursor:pointer;

    font-size:8pt;

    padding-left: 22px;
    padding-right:22px;
    padding-top: 3px;
    padding-bottom: 3px;
}
A: 
<div class="search-box ActionControl">
<div class='valign'>
  <input type="text" watermarktext="Please enter a search term" value="" name="Search" id="Search" class="watermarkOn">
</div><div class='valign'>
  <a href="/search/Tabs">Search</a>
</div>
</div>  

.valign{
  display:table-cell;
  vertical-align:middle;
  height:20px;
}
fredley
Thanks @fredley, but I try to avoid the use of tables for layout
DaveDev
-1: First of all, tables!? Secondly, valign is not a valid CSS property
Yi Jiang
Ok ok, I got rid of the table. The point is table cells are the only thing you can use vertical-align with.
fredley
@fredley: that's completely wrong - vertical-align also applies inline-level elements.
Bobby Jack
Yes, but the height property does not, meaning it's inconsistent.
fredley
How so? `height` can apply to an inline element.
Bobby Jack
http://www.w3.org/TR/CSS2/visudet.html#the-height-property : "This property does not apply to non-replaced inline-level elements."
fredley
@fredley: Hmmm... good point! display: inline-block fixes that - that's not too different from your display: table-cell, of course. I wonder why height has an effect on the input element (in Firefox), though.
Bobby Jack
I always use table-cell for vertical-align, just to be on the safe side...
fredley
A: 
#search, .search-box a { vertical-align: middle; display: inline-block; }
Bobby Jack
A: 

This is a quick fix... it was only a pixel out to my eyes...

#SearchForm .search-box a
{
    ... (Your existing styles)
    position: relative;
    top: -0.1em;
}

Using vertical-align doesn't work for me, so this just shims it.

Sohnee
That won't align when font size is changed
Bobby Jack
Using em measurements solves this problem. Example updated and tested at many different text-zooms in Firefox.
Sohnee
In which browser didn't vertical-align work? Works in FF and should work in IE 8. In this case, the vertical alignment is probably non-critical so I'd suggest that's 'good enough'
Bobby Jack
Actually, vertical-align works for me, even in IE7. I'd suggest that's a better approach than trying to tweak the positioning - vertical-align is a bit more explicit and also more robust if other changes cause height of either element to change.
Bobby Jack
I'm using Firefox 3.5.30729, the button still glues to the bottom in comparison to the input.
Sohnee
@Sohnee: Even using the style in my answer? It works for me.
Bobby Jack