【问题标题】:Align the text with differing fontsizes in two adjacent div blocks将两个相邻 div 块中不同字体大小的文本对齐
【发布时间】:2015-07-01 19:03:01
【问题描述】:

我有以下代码:http://jsfiddle.net/eNzjZ/81/

<style>
.bigLabel {    
   font-size: 128px;    
}

.smallLabel {    
   font-size: 64px;    
}

</style>
<div>
    <div style="position: absolute; left: 0px; top: 0px; width: 102px; height: 170px; z-index: 216614; overflow: visible; cursor: default;">
        <div>
            <table cellspacing="0" cellpadding="0" width="102px" height="170px">
                <tbody>
                    <tr>
                        <td class="bigLabel" style="padding:0px;background-color:yellow;" align="bottom" valign="bottom">T32</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <div style="position: absolute; left: 210px; top: 0px; width: 400px; height: 170px; z-index: 216632; overflow: visible; cursor: default;">
        <div>
            <table cellspacing="0" cellpadding="0" width="400px" height="170px">
                <tbody>
                    <tr>
                        <td class="smallLabel" style="padding:0px;background-color:orange;" align="bottom" valign="bottom">T0.00 0.00</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

问题是两个块中文本的底部没有对齐。 大字体比小字体高。

有没有可能,只改变css或者style属性,让这两段文字底部对齐?

【问题讨论】:

  • 你为什么把它弄得这么复杂?你需要这张桌子吗?或者只是如图所示的输出?
  • 别名说什么.. 为什么是表等?对于您要实现的目标,似乎完全没有必要!
  • 我无法控制 html,它是由框架呈现的

标签: css html fonts font-size


【解决方案1】:

您可以为具有较大字体大小的文本添加行高。

<td class="bigLabel" style="padding:0px;background-color:yellow; line-height: 115px;" align="bottom" valign="bottom">T32</td>

Jsfiddle

【讨论】:

  • 这很好用,虽然 line-height 和 font-size 之间有什么关系? 115 line-height好像是随便选的?更改字体大小会使所有内容再次倾斜。没有适用于所有字体大小的解决方案吗?
猜你喜欢
  • 2013-04-05
  • 2017-06-25
  • 1970-01-01
  • 1970-01-01
  • 2021-12-20
  • 1970-01-01
  • 1970-01-01
  • 2013-08-27
  • 1970-01-01
相关资源
最近更新 更多