Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align the text middle of BUTTON

Tags:

html

css

Can you anyone please help me to code this below one

This is my current code

<div id="loginBtn" class="loginBtn"><span>Log in</span></div> 

div tag have loginBtn class and span tag having "log in" text in html page

.loginBtn {     background:url(images/loginBtn-center.jpg) repeat-x;     width:175px;     height:65px;     margin:20px auto;     border-radius:10px;     -webkit-border-radius:10px;     box-shadow:0 1px 2px #5e5d5b; } 

I created the button using 1px image. Now i am unable to place the "log in" text middle of the image can any one help me complete the code

text is displaying left top corner. Please help me.

like image 940
PAM Avatar asked Nov 04 '12 10:11

PAM


People also ask

How do you align text in the middle of an element?

Center Align Text To just center the text inside an element, use text-align: center; This text is centered.

How do I center text in a button in bootstrap?

Answer: Use the text-center Class You can simply use the built-in class . text-center on the wrapper element to center align buttons or other inline elements in Bootstrap.

How do I center text in the middle of my navigation bar?

You need to take the float:left off of both your #nav and li elements. Then add display:inline-block; to both. Next add your text-align:center to the #nav .


2 Answers

You can use text-align: center; line-height: 65px;

Demo

CSS

.loginBtn {     background:url(images/loginBtn-center.jpg) repeat-x;     width:175px;     height:65px;     margin:20px auto;     border-radius:10px;     -webkit-border-radius:10px;     box-shadow:0 1px 2px #5e5d5b;     text-align: center;  <--------- Here     line-height: 65px;   <--------- Here } 
like image 124
Mr. Alien Avatar answered Oct 03 '22 20:10

Mr. Alien


This is more predictable then "line-height"

.loginBtn {      background:url(images/loginBtn-center.jpg) repeat-x;      width:175px;      height:65px;      margin:20px auto;      border-radius:10px;      -webkit-border-radius:10px;      box-shadow:0 1px 2px #5e5d5b;  }    .loginBtn span {      display: block;      padding-top: 22px;      text-align: center;      line-height: 1em;  }
<div id="loginBtn" class="loginBtn"><span>Log in</span></div>

EDIT (2018): use flexbox

.loginBtn {     display: flex;     align-items: center;     justify-content: center; } 
like image 33
Tymek Avatar answered Oct 03 '22 18:10

Tymek