-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
  • 249,100
  • 51
  • 377
  • 410
Philip
  • 409
  • 5
  • 13

5 Answers5

0

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

Rafael Umbelino
  • 771
  • 7
  • 14
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,280
  • 6
  • 21
  • 40
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,184
  • 3
  • 27
  • 38
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
  • 4,992
  • 2
  • 14
  • 25
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