Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Try to align a span and an input

Tags:

html

css

input

I have two buttons, one implemented as an input, the other as a span. They are put side by side with:

{ display:inline-block; }

The buttons are rendered from a customized tag and a class name is added dynamically in jsp. In css, there are some definition for shadow, for background gradient, for padding, and for font. They do use some CSS3 like border-radius.

But in Firefox, the height of the span button is 18 while the input 20. Interestingly, the height of them in IE 8 are both 25px, why?

Now I need them to be of the same height and aligned horizontally.

Update: Now I have those two buttons in jsfiddle. Use height:22px; and vertical-align:top; won't help much.

http://jsfiddle.net/gBeCP/

like image 942
dunfa Avatar asked Sep 09 '13 17:09

dunfa


People also ask

Can you put a span in an input?

Wrap both your input and your span inside a container, position this container as relative, and the span as absolute. You can now do whatever you like with the span.

How do I align an item inside a span?

Text Align To center an inline element like a link or a span or an img, all you need is text-align: center . For multiple inline elements, the process is similar. It's possible by using text-align: center .

How do I right align a span in HTML?

If you want to align a <span> element to the right of the <div>, you can use some CSS. Particularly, you need to use the float property with the “right” and “left” values.


2 Answers

Try setting the vertical-align:top on the input tag. I recommend specifically setting the dimensions in px as this will prevent the browser from applying defaults.

like image 148
beautifulcoder Avatar answered Nov 15 '22 05:11

beautifulcoder


I think I have it done.

Answer in this page indicates that FF treats the padding differently in submit type of input and a span. CSS padding added to height/width for <input type='submit'>

My solution is to set a min-height of both input and span, then use vertical-align:middle; to have them aligned. Finally play around the padding number to have the text on the buttons aligned.

like image 42
dunfa Avatar answered Nov 15 '22 05:11

dunfa