-2

I have a text that I want to center. I've googled it and I tried some techniques, such as table display, but none of them works.

The nearest I've been to center it, is with the following CSS:

#wrapper {
    position: fixed;
    width: 500px;
    top: 45%;
    left: 30%;
}

With trial and error...

And, of course, depending on the screen, the error is more, or less evident.

Julen
  • 1,024
  • 1
  • 13
  • 29

2 Answers2

2

You can use CSS3's transform: translate(-50%, -50%); after you set your element at top:50%; left: 50%;

.absoluteCenter{
  background:red;
  padding:24px;

  position:absolute;
  top:50%;
  left:50%;
  transform: translate(-50%, -50%);
}
<div class="absoluteCenter">HELLO WORLD</div>
Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
-2

try the following:

#wrapper{
//all of the other properties
text-align:center // should center your text

}