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>
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.
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.
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!
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!
.testbutton { display: inline-flex; align-items: center; }
You can use flexbox (check browser support, depending on your needs).
Try adding the property line-height: 22px;
to the code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With