-4

In the below image please take a look at the REQUEST FORM (inside green background) , it's aligned over top, instead I need to align in centered vertically

CSS style used ,

.rtitle {
background-color: Green;
width: 300px;
height: 50px;
border-radius: 25px;
font-size: 30px;
padding-right: 10px;
padding-left: 10px;
text-align: center;
font-weight: bold;
}

I need a exactly centered div style using css please help.

David Thomas
  • 240,457
  • 50
  • 366
  • 401
Philip
  • 331
  • 3
  • 12

5 Answers5

0

The easy way to fix this is add a padding-top in your style.

Rafael Umbelino
  • 654
  • 7
  • 13
0

When I use your styling on a button it is in the center. It could be some other styling that you have that does this. Or something in your html.

.rtitle {
background-color: Green;
width: 300px;
height: 50px;
border-radius: 25px;
font-size: 30px;
padding-right: 10px;
padding-left: 10px;
text-align: center;
font-weight: bold;
}
<button class="rtitle">Hello</button>
Naomi
  • 1,150
  • 3
  • 17
  • 35
0

Add the following in your CSS style:

button p {
margin: auto
}

And remove

text-algin:center

Plus the padding from .rtitle style and add your text between <p> </p> tag.

devpro
  • 16,074
  • 3
  • 26
  • 39
0

The answer is quite simple, add a line-height equal to height to your class:

.rtitle {
    background-color: Green;
    width: 300px;
    height: 50px;
    border-radius: 25px;
    font-size: 30px;
    padding-right: 10px;
    padding-left: 10px;
    text-align: center;
    font-weight: bold;
    
    line-height: 50px; /* ADD */
}
<div class="rtitle">REQUEST FORM</div>

Works all the time for any font (unless you have meddled with vertical-align)

Rene van der Lende
  • 3,160
  • 1
  • 13
  • 21
0

You need to put the text inside into a span

Then on the span use

.span {top: 50%; position: relative; }

https://jsfiddle.net/zt31ra3k/

DM98
  • 83
  • 6