Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html vertical align the text inside input type button

Tags:

html

css

I'm trying to create a button with height of '22px' , and that the text inside the button will be vertically aligned in the center of the button. I tried everything , and can't find out how to do it.

how can this be done?

UPDATE: this is my code:

CSS:

.test1 label {     float: left;     clear: left;     width:31%;     margin-right:-2px; } .test1 input {     float:left;     width:69%;     margin-right:-2px; } .testbutton {     float:left;     margin-left: 10px;     height: 22px;     line-height: 22px;     text-align:center;     background-color:#fbfbfb;     border:1px solid #b7b7b7;     color:#606060;     cursor:pointer;     display:inline-block;     font:bold 12px/100% Arial, sans-serif; } 

HTML:

<div class="test1"> <label for="test" title="test">test</label>                                 <input style="width:18px; float:left;" type="checkbox" name="test" id="test" tabindex="5" /> <input class="testbutton" id="testbutton" style="width:60px;"type="button" value="Import" /></div> 
like image 888
user590586 Avatar asked Mar 03 '11 18:03

user590586


People also ask

How do I align text inside a button in HTML?

We can center the button by using the following methods: text-align: center - By setting the value of text-align property of parent div tag to the center. margin: auto - By setting the value of margin property to auto.

How do I align text vertically in HTML?

Use the line-height Property to Align Text Vertically in CSS If we have single-line text, we can use the line-height property to align the text vertically within a div . The line-height CSS property sets the height of a line box. It is used to set the distance between lines of text.

How do I center text vertically in a button CSS?

Use line-height to center it vertically. I usually use the same value as its height. Works only when you know the height. I set height to 0 and line-height to zero and this worked!

How do you align text in input tag?

To have text-align:center work you need to add that style to the #siteInfo div or wrap the input in a paragraph and add text-align:center to the paragraph. Show activity on this post. you can put in a table cell and then align the cell content. Don't use tables for formatting!


2 Answers

Using flexbox:

.testbutton {   display: inline-flex;   align-items: center;  } 

You can use flexbox (check browser support, depending on your needs).

like image 146
Pensierinmusica Avatar answered Sep 18 '22 14:09

Pensierinmusica


Try adding the property line-height: 22px; to the code.

like image 41
JAiro Avatar answered Sep 20 '22 14:09

JAiro