Randomblue
Randomblue

Reputation: 116283

CSS vertical text centering

The smiley face (when you click the link) is a little towards the bottom (with respect to the black box) in the following:

http://jsfiddle.net/UzvWc/3/

HTML

<div id="message">:)</div>

CSS

#message {
    padding:0px;
    opacity:0.7;
    -webkit-border-radius:5px;
    background-color:black;
    color:white;
    width:200px;
    position: absolute;
    left: 50%;
    margin-left: -100px;
    top: 50%;
    margin-top: -150px;
    text-align: center;
    font-size: 200pt;
    display: none;
}

How can I have that smiley right in the center?

Upvotes: 1

Views: 312

Answers (2)

Jason Gennaro
Jason Gennaro

Reputation: 34855

All you need to do is add some padding-bottom.

I added 25px. Adjust as necessary.

http://jsfiddle.net/jasongennaro/UzvWc/19/

Upvotes: 0

Warface
Warface

Reputation: 5119

How about this ?

http://jsfiddle.net/UzvWc/5/

HTML

<div id="message">:)</div><a id="showmessage" href="#">Show smiley</a>

CSS

#message {
    opacity:0.7;
    -webkit-border-radius:5px;
    background-color:black;
    color:white;
    width:200px;
    position: absolute;
    left: 50%;
    margin-left: -100px;
    top: 50%;
    margin-top: -150px;
    text-align: center;
    font-size: 200pt;
    display: none;
    padding-bottom:45px;
}

Upvotes: 2

Related Questions