Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
968 views
in Technique[技术] by (71.8m points)

css - center vertically the content of a div

I have this div:

HTML:

<div draggable="false" id="coffe">Free coffee</div>

CSS:

div {
    position: absolute;
    overflow: auto;
    text-align: left;
    font-size: 23px;
    color: rgb(26, 66, 108);
    font-family: roboto, Helvetica;
    font-style: normal;
    font-weight: bold;
    -webkit-transition: none;
    transition: none;
    left: 0px;
    top: 67.125px;
    width: 1029.25px;
    height: 234.93749999999997px;
    opacity: 1;
    background: grey;
}

And I need to vertically center its content, which is "free coffee".

How can I do this? I tried with vertical-align: middle; but it doesn't work.

This is the fiddle file: http://jsfiddle.net/2Mb39/

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Specify a line-height that matches the <div>'s height:

line-height: 235px;

See this jsFiddle Demo


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...