Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS centering the text

  • This topic is empty.
Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #39855
    nuodas159
    Participant

    Hello. How to do text in center, center. I mean this text-align: center; is centering in width page. How to center the text in height page? BTW if the page is height: 100%, min-height: 100%, max-height: 100%

    #110098
    Paulie_D
    Member
    #110100
    nuodas159
    Participant

    #message-activate {
    clear: left;
    display: table;
    text-align: center;
    display: table-cell;
    vertical-align: middle;
    }

    {MESSAGE_TITLE}

    {MESSAGE_TEXT}

    {S_HIDDEN_FIELDS}
     

    So how to do? I don’t understand there. -.- I mean not working.

    #110101
    Taufik Nurrohman
    Participant

    This works for me. Just for single line, use `line-height`:

    .text {
    display:block;
    width:500px;
    text-align:center; /* center horizontally */
    height:200px;
    line-height:200px; /* same with height (center vertically) */
    }
    #110102
    nuodas159
    Participant

    I was saying that height is 100% with line-height: 200px deosn’t centering.

    #110103
    nuodas159
    Participant
    #110104
    Paulie_D
    Member

    It is working.

    Look, put whatever code you are using into Codepen or jsFiddle or provide us with a live link.

    #110106
    Taufik Nurrohman
    Participant

    Here it is ⇒ http://jsfiddle.net/tovic/hJtpF/3162/

    If you make a modal window (I guess) with the involvement of JavaScript, it would be better to use them for centering the element:

    $(document).ready(function() {
    var $el = $('#message-activate'),
    el_w = $el.outerWidth(),
    el_h = $el.outerHeight();
    $el.css({
    'position': 'absolute',
    'top': '50%',
    'left': '50%',
    'margin-left': '-' + (el_w / 2) + 'px',
    'margin-top': '-' + (el_h / 2) + 'px'
    });
    });

    http://jsfiddle.net/tovic/hJtpF/3163/

    #110107
    chrisburton
    Participant

    I also have a script someone made for me. Although it’s specifically for an image, you can change the jQuery a bit to fit your needs. http://christopherburton.net/includes/center.js

    #110121
    nuodas159
    Participant

    Why not working like this?

    .block {
    clear: left;
    text-align: center;
    }

    .block:before {
    content: ”;
    display: inline-block;
    height: 100%;
    vertical-align: middle;
    }

    #message-activate {
    display: inline-block;
    vertical-align: middle;
    }

    {MESSAGE_TITLE}

    {MESSAGE_TEXT}

    {S_HIDDEN_FIELDS}
     

    P.S. Thanks for ChristopherBurton and Hompimpa. BTW why not working?

    #110123
    Kitty Giraudel
    Participant

    Seriously, just make a JSFiddle…

    #110132
    nuodas159
    Participant
    #110134
    chrisburton
    Participant
    #110154
    nuodas159
    Participant

    Nope I need this #message-activate to be vertical center

    #110149
    Kitty Giraudel
    Participant

    It is.

Viewing 15 posts - 1 through 15 (of 18 total)
  • The forum ‘CSS’ is closed to new topics and replies.