html - Mac/PC 上的字体渲染/行高问题(元素外部)

标签 html vertical-alignment css css-tables

设计

信息小部件的内容应该在中间垂直对齐:

Original PSD Design


编码设计

Windows:Chrome 20/FF 14/IE 9

Windows Coded Design

Mac(Lion/Mt.Lion):Chrome/FF

Mac Coded Design


代码

HTML

<div class="info">
    <div class="weather display clearfix">
        <div class="icon"><img src="imgs/icons/thunderstorms.png" align="Thunderstorms" /></div>

        <div class="fl">
            <p class="temperature">82&deg; / 89&deg;</p>
            <p class="conditions">Thunderstorms</p>
        </div>
    </div>
    <div class="time display">
        <p>11:59 <span>AM</span></p>
    </div>
    <div class="date display clearfix">
        <p class="number fl">23</p>
        <p class="month-day fl">Jun <br />Sat</p>
    </div>
</div><!-- //.info -->

CSS

.info {
    display:table;
    border-spacing:20px 0;
    margin-right:-20px;
    padding:6px 0 0;
}
    .display {
        background-color:rgba(255, 255, 255, .2);
        border-radius:10px;
        -ms-border-radius:10px;
        color:#fff;
        font-family:"Cutive", Arial, sans-serif;
        display:table-cell;
        height:70px;
        vertical-align:middle;
        padding:3px 15px 0;
    }
        .display p {padding:0;line-height:1em;}
        .time, .date {padding-top:5px;}
            .time p, .date .number {font-size:35px;}
            .time span, .display .month-day, .conditions {
                font-size:14px;
                text-transform:uppercase;
                font-family:"Maven Pro", Arial, sans-serif;
                line-height:1.15em;
                font-weight:500;
            }
            .display .month-day {padding-left:5px;}
            .icon {float:left;padding:0 12px 0 0}
            .display .temperature {font-size:24px;padding:4px 0 0;}
            .display .conditions {text-transform:none;padding:2px 0 0;}
    .lt-ie9 .display { /* IE rgba Fallback */
        background:transparent;
        filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#20ffffff,endColorstr=#20ffffff);
        zoom:1;
    } 

问题

查看上面的编码设计图片,您可以看到它是如何偏离对齐的。进一步查看后,文本呈现在 mac 上的元素之外。

window

Windows Coded Design Alignment

Mac

Mac Coded Design Alignment


注意事项

我通过 Google Web Fonts 样式表嵌入字体。


已测试

我尝试了以下方法:

  • 为每个元素设置行高。
  • 为每个元素设置字体粗细。
  • 设置每个元素的高度。
  • 每个元素上的高度/padding-top 的组合。
  • 使用百分比/em/px 进行填充。

似乎无论我尝试什么,内容永远不会在 mac 和 pc 上完美居中对齐。


我的问题

有可能以简单的方式实现我想要做的事情吗?

我是否应该放弃 display:table-cell; 路由并为每个元素和子元素设置特定的高度/填充?我仍然会遇到两个操作系统之间的填充/间距问题。

我应该将此问题归类为哪一类?行高?表细胞?操作系统?等等……

提前致谢!

最佳答案

如果使用不同的字体 (Arial) 可以解决问题,则问题出在字体上,而不是 CSS 上。正如您所注意到的,不同浏览器的字体渲染不同。

一种可能的解决方案是下载 Cutive 字体(我看到它有 SIL 许可证),然后通过 Font Squirrel 字体生成器运行它。在“专家”模式下,有一个选项可以“修复垂直指标”,这可能正是您正在寻找的。

关于html - Mac/PC 上的字体渲染/行高问题(元素外部),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11726442/

相关文章:

css - 当 body 高度为 : 100% without absolute pos 时垂直居中 div

html - textarea 旁边的中心 div

html - CSS:如何水平居中和垂直居中对齐文本内容?

html - anchor 链接滚动到不正确的位置

javascript - 设置 AngularJS 时遇到问题

html - html 表单标签中的操作 ="#"中的哈希值意味着什么

CSS 选择器 * 不适用于 Twitter Bootstrap

javascript - 未知的 JavaScript 错误 - 函数仅运行第一行代码

css - 如何将这些 div 均匀分布?

html - IE 与 Chrome - 图像宽度/Div 宽度