- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
经过几个小时的调试和摸索,我发现不可能在浏览器中一致地垂直对齐垂直指标较差的字体。如果字体的垂直度量很差,它可能会渲染得太远或太远,并且看起来很糟糕,尤其是在按钮内部。仅靠CSS是没有办法解决这个问题的。
您可以通过此网站上的测试检查字体的垂直尺寸:http://levien.com/webfonts/vmtx/ (只需下载测试并替换字体即可。)
这是我得到的结果。上面的指标较差,下面的指标正确:(两者都有固定的行高)
Fontsquirrel在专家模式下的生成器中提供了对不良垂直指标的修复。不幸的是,我必须使用的字体属于 Microsoft (SegoePrint),并且在 Fontsquirrel 生成器上被列入黑名单。
更新:
为了让问题更清楚..这就是我现在面临的情况:
我试图将按钮的文本垂直对齐到中间(见下图)。在左侧,您可以看到它在 Android 上的 Chrome 中的呈现方式,在右侧,您可以看到它在 Windows 上的 Chrome 中的呈现方式。 Arial 和最常见的字体都很好地居中,Segoe Print 则不然..
我在CSS中尝试了不同的对齐方法,但没有一个一致地工作。我还在 fiddle 中尝试了它,得到了相同的结果,但我无法显示,因为字体不是免费的。这是一个特定于字体的问题,唯一的解决方案似乎是修复字体本身。
这是按钮的 CSS(值是虚构的):
div.parent {
height:40px
}
h3 {
line-height: 40px;
font-size: 14px
}
最佳答案
我使用 Helevetica Neue 的许可版本,我还注意到其常规字体和粗体字体之间的按钮存在差异。我可以通过将 descent-override: 0%;
添加到粗体版本的 @font-face
声明中来解决此问题。截至撰写本文时,并非所有浏览器都支持(不支持 IE 11 或 Safari),但 Mac 通常在本地安装了 Helvetica Neue,因此我首先检查本地版本,然后只剩下 IE 11 不受支持(像往常一样)。
https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/descent-override
还有 ascent-override
可供使用,这对于某些字体可能会更好。
// index.scss
/* CDN version - we need to add descent-override to the CDN version only */
@font-face {
font-family: "font-primary";
font-style: normal;
font-weight: 700;
src:
url("<MY-CDN-URL>.woff2")
format("woff2"),
url("<MY-CDN-URL>.woff")
format("woff");
font-display: swap;
descent-override: 0%;
}
/* Local version */
@font-face {
font-family: "font-primary-local";
font-style: normal;
font-weight: 700;
src: local("Helvetica Neue Bold");
font-display: swap;
}
$font-primary: "font-primary-local", "font-primary", "Helvetica Neue", "Helvetica", "Arial", sans-serif;
之前:
之后:
关于fonts - 字体: poor vertical metrics cause inconsistent line-height rendering across browsers. 解决方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33633992/
获取错误 ORA-00932: inconsistent datatypes: expected CHAR got NUMBER 00932. 00000 - "inconsistent dataty
我的main.sass中有这个: #thing { -moz-box-sizing: border-box; -webkit-box-sizing: border
在 Python 中,为什么 [:] 切片操作的行为不一致? 它对于列表和字符串的行为有所不同。 对于列表,它给出一个副本列表对象,对于字符串,它给出相同的字符串对象。 我觉得这令人困惑,违反直觉。有
在检查和测试正则表达式的各个方面时,我偶然发现了一种奇怪且“不一致”的行为。我试图在正则表达式中使用一些代码,但同样的行为也适用于使用 void 代码块。 尤其是最让我感动的是,当我互换 :g 和 :
已连接两个支持蓝牙的设备。一个通过outputStream向另一个发送周期性时间戳(writeTime),另一个通过inputStream检索writeTimes并附加自己的时间戳(readTime)
我有以下距离矩阵: delta = [[ 0. 0.71370845 0.80903791 0.82955157 0.56964983 0. 0.
我正在使用 recyclerView 并将数据加载为 arrayList。如果 arrayList 少于 7 个项目,则不会发生崩溃。 否则,我会遇到这个 fatal error : java.lan
为什么结果是: double a = 0.0/0.0; double b = 0/0.0; = NaN 但是结果例如: double e = 0.1/0.0; double e = 12.0/0.0;
这是我的 Java 1.6 类: public class Foo { private ArrayList names; public void scan() { if (names
我正在制作一个使用 encog 预测足球比赛结果的程序。我创建了一个神经网络,使用弹性传播训练方法使用 90 场比赛的数据对其进行训练。我将比赛结果标记为 1 表示主场获胜,0 表示平局,-1 表示客
我正在向我的 App 类中正在进行的 WPF 应用程序添加一些可绑定(bind)的 CLR 属性,但由于这个不一致的可访问性错误,我无法编译。 Inconsistent Accessibility:
我正在尝试使用带有以下参数的 solve.QP 函数(来自 quadprog 包)运行优化 R = matrix( c( 2.231113e-05,-4.816095e-05,-5.115287e-0
我的 solr 架构中有以下两个字段: 当我在启用 facet 的情况下发出请求(faceting on brand_id) http://example.com/solr/select?wt=j
我在 UIView 上有一个 UIButton。我想以编程方式确定显示 View 时在按钮内显示哪个图像。我已经重写了 UIView 中的 drawRect 方法并使用 setImage 来显示所需的
在常规中: println 'test' as Boolean //true println 'test'.toBoolean() //false println new Boolean('test'
例如,在 message.properties 中空白字段的默认 i18n 消息是: default.blank.message=Property [{0}] of class [{1}] canno
我正在尝试使用 array_multisort() 在其子数组的基础上对数组进行排序功能...... 在尝试的同时; print_r($mar); echo ''; $arr2 = array_mul
我正在使用 MALLET 来训练 ParallelTopicModel。训练后,我得到一个 TopicInferencer,取一个句子,通过推理器运行 15 次,然后检查结果。我发现对于某些主题,每次
1) 为什么在 JavaScript 中存在这种不一致 - 我期望第四行也返回 11: (function(n, m) { n = n + m; return n })(3, 8)
上下文: 我有一个小部件,它基本上由一个包装了一堆 TextView 的 RelativeLayout 组成。这是我希望小部件的外观,然后是 XML 布局代码: 问题:我
我是一名优秀的程序员,十分优秀!