无法使用大字体居中文本

时间:2014-10-31 01:13:53

标签: html css

我尝试过line-height等,但似乎当内容有一个大字体时,它会在上方和下方产生额外的空白区域。有没有办法让容器获得内容的精确高度,不包括上面的空格?和其他浏览器一样吗?我现在正在大量脱发。谢谢!

这是css:

.raf {
    margin: 20px auto;
    height: 100px;
    width: 200px;
    overflow: hidden;
    border: solid 1px #000;
    text-align: center;
    font-size: 0;
    display: block;
    position: relative;
}

.text {

    font-family: "Myriad Pro", "Gill Sans", "Gill Sans MT", Calibri, sans-serif;
    color: #000000;
    font-size: 52px;
    font-weight: bold;
    display: inline-block;
    position: absolute;
    letter-spacing: 17px;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    width: 94px;
    height: 54px;
    overflow: hidden;
}

.innerText {
    float: left;
    overflow: hidden;
    border:solid 1px #CCC;
}

HTML:     

    <div class="text">

        <div class="innerText">

            39

      </div>

    </div>

</div>

1 个答案:

答案 0 :(得分:0)

.text {
font-family: "Myriad Pro", "Gill Sans", "Gill Sans MT", Calibri, sans-serif;
color: #000000;
font-size: 52px;
font-weight: bold;
display: inline-block;
position: absolute;
letter-spacing: 17px;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
width: 111px;
height: 54px;
overflow: hidden;
line-height: 1;
}
.innerText {
float: left;
overflow: hidden;
border: solid 1px #CCC;
padding-left: 17px;
}