-1

What ways of vertical text centering inside a div contaner do you know?

Vector
  • 259
  • 1
  • 3
  • 4

2 Answers2

1
  1. text-align:center;

  2. margin:0 auto; //tag needs to have a with

amosrivera
  • 26,114
  • 9
  • 67
  • 76
  • Not OP, but what is the difference between 'margin: 0 auto 0 auto' and 'margin: 0 auto'? –  Jan 15 '11 at 07:00
  • And what about *vertical* text? – Sarfraz Jan 15 '11 at 07:01
  • there is no difference, using margin:0 auto; is the short-hand version see: http://www.dustindiaz.com/css-shorthand/ – amosrivera Jan 15 '11 at 07:01
  • @kevin: `margin: A` becomes `margin: A A A A`. `margin: A B` becomes `margin: A B A B`. `margin: A B C` becomes `margin: A B C B`. – Steven Jan 15 '11 at 07:04
0
  1. If a single line of text, setting the line height of the div to be the height of the div.

  2. If the height of the content is known, position it absolutely - top: 50%, margin-top: -(half the height of the content) pixels.

sevenseacat
  • 24,699
  • 6
  • 63
  • 88