Contact: Web / Voice / Email / Tips
Simple Thoughts Blog - Java and Web Technologies

Simple solutions for complex problems.

 

How To Perfectly Align Image Button With HTML Input Textbox

May 1st, 2006 by Angsuman Chakraborty

The form element input with type text strangely refuses to align with an adjacent image button (input element of type image). The problem is rather hard to solve as regular methods like using align or margin or padding or even adding whitespace to the image fails. Here is a surprisingly simple solution to this problem. But first lets take a look at the problem.

The input textbox above is misaligned with the image button above as you can see. The code is:

<form>
  <input type=”text” name=”foo” value=”bar”>
  </input><input type=”image” src=”http://www.utexas.edu/learn/forms/graphics/button.gif” ></input>
</form>

The solution is deceptively simple. Here is the code which works:

<form>
  <input type=”text” name=”foo” value=”bar”>
  </input><input style=”position:absolute” type=”image” src=”http://www.utexas.edu/learn/forms/graphics/button.gif”></input>
</form>

Here is the demo:


Filed under Headline News, How To, Tech Note, Web | | RSS 2.0 | Trackback this Article | Email this Article

You may also like to read

»Japanese Corporations Dominate US Patent Registrations in 2005; IBM Still in Lead
»48 Indian Companies in Forbes Global 2000 (Top Companies Worldwide)
»Translator Plugin Gold Languages Supported Matrix
»Firefox Tip: How To Change The Default Home Page Location
»Translator Plugin Pro Languages Supported Matrix
»What is Your Favorite Programming Language?
»How To Get Top Level Domain Name Free
»Web 2.0 - Next Generation Internet or Hype?
»Translation Matrix of 14 Languages Supported in Translator Plugin Pro Version 4.0
»Cross-Site Scripting Vulnerability in Apache mod_imap Module
»Taragana Products Store
»Computer Hardware Recommendations (India)
»Free Unlimited Image Hosting
»Taragana's Del.icio.us mp3 Player WordPress Plugin
»WordPress 2.0/1.5.x Hack: How to trim the fat resource hogging Admin DashBoard

10 Responses to “How To Perfectly Align Image Button With HTML Input Textbox”

  1. bemular Says:

    what about aligning them both at the middle vertically?

  2. Kat Says:

    align=absmiddle is deprecated.

    Can anyone explain why this behaviour happens, and why position: absolute solves it?

    I’m constantly coming across CSS problems but the solutions don’t leave me any the wiser :(

  3. Andrea Says:

    Kat: This is probably due to the “image baseline” issue, where there is whitespace at the bottom of an image. Since images are inline objects, they sit on the baseline and not at the bottom of the containing block. Changing the style to “display: block;” would also work in an example like this.

  4. Jovi Says:

    Ive been trying this and ive figured out that puting ur elements in a table, each in a différent cell is doing the alignment very well.
    Cause playing wit absolute positioning in a table can end up really messy.

    ( normal textbox is setting height and text size from my CSS style sheet )

  5. Nick Says:

    using vertical-align: text-bottom is the best way to achieve the desired effect

  6. weeman Says:

    Bonjour,
    Sous IE6, le bouton Go est 1 pixel au-dessus du input
    Tout le monde le voit :o

  7. Andrew Says:

    Fantastic - I’ve used this to align PayPal shopping cart buttons so they don’t affect the page layout below them. It’s a problem with PayPal that has been bugging me for ages! Thanks.

  8. chk Says:

    Bonjour, you can solve the 1 pixel problem easily.

    Complete Code:

  9. chk Says:

    asp:ImageButton ID=\

  10. slr722 Says:


    Works a charm!

  11. Curly Says: Your comment is awaiting moderation.

    This has been a booger…
    Didn’t work for me.

    But I did use style=”vertical-align: middle” which worked like a charm. ;-)

Looking forward to hear your thoughts.



Please enter the code shown below ( to verify that you are human ) before you click Submit Comment.

No. 1 method to ethically increase your blog traffic and reach.

Translate

Translate to EnglishÜbersetzen Sie zum Deutsch/GermanPřeložit do Čech/CzechOversætte hen til Dansk/DanishKääntää jotta Finnish/FinnishLefordít -hoz Magyar/HungarianÞýða til Íslenska/IcelandicTraducir a Latinoamericano Español/Latin American Spanishtagapagsalin sa Filipino/FilipinoTłumaczyć wobec Polski/PolishA traduce la spre Român/RomanianPrevesti za Srpski/Serbiantolmačiti v slovenski/SlovenianÖversätta till Svensk/SwedishChyfieitha at Cymraeg/Welshtercüme etmek -e doğru Türk/TurkishPrevesti to Hrvatski/CroatianПревеждам към Българин/BulgarianTraduzca al Español/SpanishTraduisez au Français/FrenchTraduca ad Italiano/ItalianTraduza ao Português/Portuguese日本語に翻訳しなさい /Japanese한국어에게 번역하십시오/Korean中文翻译/Chinese Simplifiedترجمة الى العربية/ArabicVertaal aan het Nederlands/DutchΜεταφράστε στα ελληνικά/GreekПереведите к русскому/RussianOversetter til Norsk/Norwegian中文翻译/Chinese TraditionalTraduzir a Língua portuguesa brasileira/Brazilian PortugueseReddo ut Latin/Latin

Taragana Network

»Ctrl-S
»Enterprise Blog
»Free Book on Eye Care by Natural Therapy
»Health Care Blog
»Hot Computer Jobs Blog
»Pet Care & Grooming News and Tips
»Phil Law Blog
»Taragana - Software Outsourcing
»The Angsuman Chakraborty Blog
»The Diabetes Cure Blog
»The Eye Treatment Blog
»The Stem Cell Blog
»Weblog Hosting Blog
"The only real valuable thing is intuition." - Albert Einstein