-2

I have to display text in the middle of the screen. So I need the text to be vertically and horizontally aligned in the middle. The horizontal alignment is not a problem, but I don't know how to align it vertically. I have found some solutions, but they need JQuery and I'm not familiar with that yet. The text has to be in the center on every monitor and every resolution.

Temani Afif
  • 180,975
  • 14
  • 166
  • 216
sin-an
  • 3
  • 4

2 Answers2

-1

I use this css class in all my projects. Assign the class to any div container and it will show vertically and horizontally centered. Hope this works for you.

.windowCentered {
    padding: 10px;
    position : fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}
  • yes that works but you have to scroll on my page and that's not possible due to the fixed position – sin-an Jul 26 '19 at 21:50
-2

So I don't know your full situation but do the following (if it helps):

[In your CSS file] - select your text ("p" or "h1" or whatever you used). Select it by doing the following (assume you wrote your "text" in "

"):

p {

}

  • then type the following:

    p { text-align: center; }

Save the file(s) and reload it and the text should be aligned in the middle

OTHER SITUATION:

DO you mean you want to put it in the center of your WHOLE screen? Then that would be more complicated but I suggest that you try some of these things:

  • define how large your website is allowed to be (maximum)
  • take the half of this size ()
  • nest your text into a container, like
  • use CSS to put your "block" into the middle of the screen. You'd have to google the rest because unfortunately I'm not a pro. These are the things I'd try!
Tim.Kaz
  • 13
  • 1
  • 5