【发布时间】:2019-05-24 12:18:44
【问题描述】:
文本在 Safari 中的位置与在其他浏览器中的位置不同。这有什么原因吗?有没有一种风格可以确保它符合精确的测量要求。
* {
margin: 0;
padding: 0;
}
#btn_signup {
opacity: 1;
position: absolute;
width: 185px;
height: 50px;
left: 10px;
top: 10px;
overflow: visible;
}
#Rectangle_1 {
opacity: 1;
fill: transparent;
stroke: rgb(67, 66, 93);
stroke-width: 1px;
stroke-linejoin: miter;
stroke-linecap: butt;
stroke-miterlimit: 4;
shape-rendering: auto;
}
.Rectangle_1 {
position: absolute;
overflow: visible;
width: 185px;
height: 50px;
left: 0px;
top: 0px;
}
#Sign_up {
opacity: 1;
position: absolute;
left: 58px;
top: 16px;
box-sizing: border-box;
margin: 0;
padding: 0;
overflow: visible;
width: 63px;
white-space: nowrap;
text-align: center;
}
#Path_1 {
opacity: 1;
fill: rgba(0,0,0,0);
stroke: rgb(112, 112, 112);
stroke-width: 0.5px;
stroke-linejoin: miter;
stroke-linecap: butt;
stroke-miterlimit: 4;
shape-rendering: auto;
}
.Path_1 {
overflow: visible;
position: absolute;
top: 16.5px;
left: 1px;
width: 183.5px;
height: 0.5px;
transform: matrix(1,0,0,1,0,0);
}
<div id="A5">
<div id="btn_signup">
<svg class="Rectangle_1">
<rect id="Rectangle_1" rx="4" ry="4" x="0" y="0" width="185" height="50"></rect>
</svg>
<div id="Sign_up">
<span style="font-family:Helvetica;font-style:normal;font-weight:normal;font-size:18px;color:rgba(77,79,92,1);display:inherit;">Sign up</span>
</div>
<svg viewBox="12.5 0 183.5 0.5" class="Path_1">
<path id="Path_1" d="M 12.5 0 L 196 0"></path>
</svg>
</div>
</div>
在 Firefox 中,文本与行齐平。在 Safari 中会有一些像素间隙,如下图所示:
如何消除这个差距?
增加了赏金。如果您需要更清晰的信息,请提出问题。
更新:
感谢所有垂直居中的建议。我有一半的案例将通过垂直居中来修复,但其余的是顶部对齐案例。
看起来我想要的是让我的文本内容,大写高度的内容边界框与文本行的顶部边缘对齐,如图所示。
资源:
看起来这是跨平台的常见问题。
Cap height and x-height metrics are inaccurate
Vertical Metrics
【问题讨论】:
-
可能是不同的
line-height;尝试明确设置。 -
奇数。我想不出其他任何东西,我这里没有 Safari 可供测试,抱歉。改为投票。
-
要对齐字体,您需要阅读其指标,这是一种可能的方法:stackoverflow.com/questions/38242098/…
-
备注,将我的别名添加到您的 cmets 以便我收到通知。
标签: html css safari webkit typography