【问题标题】:center vertically the content of a div将 div 的内容垂直居中
【发布时间】:2014-01-27 09:24:00
【问题描述】:

我有这个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;
}

我需要将其内容垂直居中,即“免费咖啡”。

我该怎么做?我尝试使用vertical-align: middle;,但它不起作用。

这是小提琴文件:http://jsfiddle.net/2Mb39/

【问题讨论】:

标签: css center


【解决方案1】:

指定与&lt;div&gt; 的高度匹配的line-height

line-height: 235px;

看到这个jsFiddle Demo

【讨论】:

  • 没问题。如果有帮助,您可能想接受答案;)
  • 开始另一个问题,而不是移动这个问题的门柱。
猜你喜欢
  • 2014-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-21
  • 1970-01-01
  • 2017-07-29
  • 2012-04-05
  • 2013-12-17
相关资源
最近更新 更多