0

I've got the following page. http://jsfiddle.net/r1mymj25/. I'm having trouble trying to get the text in the QDetails to be placed in the middle of the DIV using CSS.

#QDetails{
   height:25px; 
   top:40px; 
   background-color:white; 
   text-align:center; 
   font-size:small; 
   border-color:black; 
   border-width:2px; 
   border-style:solid; 
   font-family: Arial, Helvetica, sans-serif; 
   vertical-align:middle;
}

I've managed to centre it but not place it in the middle. I've tried "vertical-align:middle;" but no joy. What am I doing wrong please?

codingitup
  • 149
  • 2
  • 13

3 Answers3

0

vertical-align : middle only works within tables (as far as I know).

If you include the following in your style definition it should work: line-height:25px;

Paddy
  • 33,309
  • 15
  • 79
  • 114
0

Remove top:40px(not doing anything) and apply line-height property like below.

#QDetails{
height:25px; 
background-color:white; 
text-align:center; 
font-size:small; 
border:2px solid black;
font-family: Arial, Helvetica, sans-serif; 
line-height:25px;
}

DEMO

Suresh Ponnukalai
  • 13,820
  • 5
  • 34
  • 54
0

Try this.

Create a span inside the div and then set text to the span like below

<div id="QDetails">
    <span id="msg"></span>
</div>

This is the css class

#QDetails
{
   height:25px; 
   top:40px; 
   background-color:white;
   font-size:small; 
   border-color:black; 
   border-width:2px; 
   border-style:solid; 
   font-family: Arial, Helvetica, sans-serif; 
   display: table;
   text-align:center;
}

#msg
{
   display: table-cell;
   vertical-align: middle;
}

Try this. It will make it exact.

Ganesh Gaxy
  • 657
  • 5
  • 11