- This topic is empty.
-
AuthorPosts
-
September 15, 2012 at 8:55 am #39855nuodas159Participant
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%
September 15, 2012 at 9:39 am #110098September 15, 2012 at 10:10 am #110100nuodas159Participant#message-activate {
clear: left;
display: table;
text-align: center;
display: table-cell;
vertical-align: middle;
}So how to do? I don’t understand there. -.- I mean not working.
September 15, 2012 at 10:18 am #110101Taufik NurrohmanParticipantThis 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) */
}September 15, 2012 at 10:25 am #110102nuodas159ParticipantI was saying that height is 100% with line-height: 200px deosn’t centering.
September 15, 2012 at 10:27 am #110103nuodas159ParticipantWhy not working? http://jsfiddle.net/chriscoyier/hJtpF/
September 15, 2012 at 10:48 am #110104Paulie_DMemberIt is working.
Look, put whatever code you are using into Codepen or jsFiddle or provide us with a live link.
September 15, 2012 at 11:10 am #110106Taufik NurrohmanParticipantHere 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'
});
});September 15, 2012 at 11:16 am #110107chrisburtonParticipantI 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
September 15, 2012 at 12:37 pm #110121nuodas159ParticipantWhy 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;
}P.S. Thanks for ChristopherBurton and Hompimpa. BTW why not working?
September 15, 2012 at 1:26 pm #110123Kitty GiraudelParticipantSeriously, just make a JSFiddle…
September 15, 2012 at 3:00 pm #110132nuodas159ParticipantSeptember 15, 2012 at 3:34 pm #110134chrisburtonParticipant@nuodas159 Do you mean like this? http://jsfiddle.net/hJtpF/3166/
September 16, 2012 at 2:31 am #110154nuodas159ParticipantNope I need this #message-activate to be vertical center
September 16, 2012 at 6:45 am #110149Kitty GiraudelParticipantIt is.
-
AuthorPosts
- The forum ‘CSS’ is closed to new topics and replies.