Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Center text vertically with relative height

Center text vertically with relative height

Scheduled Pinned Locked Moved Web Development
questionworkspace
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #1

    I need to center a text vertically (and horizontally) along the whole page, and for that I need to setup the height property as relative, respectively whole page. I have tried:

    body {
    font-family: Arial;
    color: #f9f9ff;
    background-color:#293138;
    }

    .center-text {
    height:100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    }

    Test
    

    How can I achieve this ?

    R Graeme_GrantG 2 Replies Last reply
    0
    • _ _Flaviu

      I need to center a text vertically (and horizontally) along the whole page, and for that I need to setup the height property as relative, respectively whole page. I have tried:

      body {
      font-family: Arial;
      color: #f9f9ff;
      background-color:#293138;
      }

      .center-text {
      height:100%;
      display: flex;
      flex-direction: column;
      justify-content: center;
      }

      Test
      

      How can I achieve this ?

      R Offline
      R Offline
      Richard Deeming
      wrote on last edited by
      #2

      Using Flexbox:

      .center-text {
      min-height: 100vh;
      display: flex;
      justify-content: center;
      align-items: center;
      }

      Demo[^] CSS Flexible Box Layout - CSS: Cascading Style Sheets | MDN[^]


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      _ 1 Reply Last reply
      0
      • _ _Flaviu

        I need to center a text vertically (and horizontally) along the whole page, and for that I need to setup the height property as relative, respectively whole page. I have tried:

        body {
        font-family: Arial;
        color: #f9f9ff;
        background-color:#293138;
        }

        .center-text {
        height:100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        }

        Test
        

        How can I achieve this ?

        Graeme_GrantG Offline
        Graeme_GrantG Offline
        Graeme_Grant
        wrote on last edited by
        #3

        _Flaviu wrote:

        How can I achieve this ?

        Take you pick: 11 Ways to Center Div or Text in Div in CSS[^]

        Graeme


        "I fear not the man who has practiced ten thousand kicks one time, but I fear the man that has practiced one kick ten thousand times!" - Bruce Lee

        _ 1 Reply Last reply
        0
        • R Richard Deeming

          Using Flexbox:

          .center-text {
          min-height: 100vh;
          display: flex;
          justify-content: center;
          align-items: center;
          }

          Demo[^] CSS Flexible Box Layout - CSS: Cascading Style Sheets | MDN[^]


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          _ Offline
          _ Offline
          _Flaviu
          wrote on last edited by
          #4

          Excellent ! It works. Thanks!

          1 Reply Last reply
          0
          • Graeme_GrantG Graeme_Grant

            _Flaviu wrote:

            How can I achieve this ?

            Take you pick: 11 Ways to Center Div or Text in Div in CSS[^]

            Graeme


            "I fear not the man who has practiced ten thousand kicks one time, but I fear the man that has practiced one kick ten thousand times!" - Bruce Lee

            _ Offline
            _ Offline
            _Flaviu
            wrote on last edited by
            #5

            I have read that post, I didn't noticed any solution with relative height, I've read not very carefully though.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups