1

i'm trying to center some text vertically and horizontal in my #modal element:

#modal
{
background: gray;
    color: white;
    white-space: nowrap;
    width: 427px;
    height: 999px;
}

http://jsfiddle.net/4js3runn/

<div id="modal">
    <span>CENTRE THIS</span>
</div>
Kshitijc
  • 21
  • 2
  • 1
    http://stackoverflow.com/questions/19461521/how-to-center-text-horizontally-and-vertically/19461564#19461564 – Josh Crozier Feb 04 '15 at 05:16
  • thanks but i need an answer in my case. I dont know css. – Kshitijc Feb 04 '15 at 05:19
  • 1
    Change #modal class to #modal { background: gray; color: white; white-space: nowrap; width: 427px; height: 999px; display: flex; align-items: center; justify-content: center; } – Sameeraa4ever Feb 04 '15 at 05:20

1 Answers1

1

see the jsfiddle code : http://jsfiddle.net/4js3runn/1/

#modal {
    background: none repeat scroll 0 0 gray;
    color: white;
    float: left;
    height: 100vh;

    position: relative;
    width: 100%;
}
.center {
    background-color: #444;
    height: 30px;
    left: 50%;
    line-height: 30px;
    margin-left: -56px;
    margin-top: -15px;
    position: absolute;
    text-align: center;
    top: 50%;
    width: 112px;
}
<div id="modal">
    <div class="center">CENTRE THIS</div>
</div>
anji
  • 344
  • 3
  • 6