{"id":10319,"date":"2022-03-21T23:35:45","date_gmt":"2022-03-21T15:35:45","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10319"},"modified":"2022-03-21T23:35:45","modified_gmt":"2022-03-21T15:35:45","slug":"css-ascent-override-descent","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2022\/03\/css-ascent-override-descent\/","title":{"rendered":"ascent-override descent-override line-gap-override\u4e00\u9505\u7aef"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10319\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=10319<\/a> \u946b\u7a7a\u95f4-\u946b\u751f\u6d3b<br \/>\n\u672c\u6587\u6b22\u8fce\u5206\u4eab\u4e0e\u805a\u5408\uff0c\u5168\u6587\u8f6c\u8f7d\u5c31\u4e0d\u5fc5\u4e86\uff0c\u5c0a\u91cd\u7248\u6743\uff0c\u5708\u5b50\u5c31\u8fd9\u4e48\u5927\uff0c\u82e5\u6025\u7528\u53ef\u4ee5\u8054\u7cfb\u6388\u6743\u3002<\/p>\n<p><script>window.wxShareImgUrl = 'https:\/\/www.zhangxinxu.com\/study\/image\/share\/202203-font-face.jpg';<\/script><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202203\/flay-font-cover.png\" width=\"484\" height=\"303\" alt=\"\u7834\u8327\u6210\u8776\" class=\"alignright thumb clip size-medium\" \/><\/p>\n<p><code>ascent-override<\/code>\u3001<code>descent-override<\/code>\u548c<code>line-gap-override<\/code>\u8fd9 3 \u4e2a CSS \u5c5e\u6027\u4f5c\u7528\u90fd\u662f\u7c7b\u4f3c\u7684\uff0c\u90fd\u662f\u5728 <code>@font-face<\/code> \u81ea\u5b9a\u4e49\u5b57\u4f53\u4e2d\u8bbe\u7f6e\u6587\u5b57\u7684\u4e0a\u3001\u4e2d\u6216\u4e0b\u95f4\u9699\u5927\u5c0f\u3002<\/p>\n<p>\u7531\u4e8e\u517c\u5bb9\u6027\u4e00\u81f4\uff0c\u4f5c\u7528\u7c7b\u4f3c\uff0c\u4f7f\u7528\u573a\u666f\u4e5f\u4e00\u81f4\uff0c\u56e0\u6b64\uff0c\u653e\u5728\u4e00\u8d77\u4ecb\u7ecd\u3002<\/p>\n<h3>\u4e00\u3001\u4f5c\u7528\u8bf4\u660e<\/h3>\n<p>\u7b80\u5355\u6765\u8bf4\uff1a<\/p>\n<p><code>ascent-override<\/code>\u548c<code>descent-override<\/code>\u7528\u6765\u91cd\u7f6e\u5b57\u4f53\u4e2d\u5185\u7f6e\u7684\u4e0a\u60ac\u7ebf\u548c\u4e0b\u60ac\u7ebf\u7684\u4f4d\u7f6e\u3002<\/p>\n<h4>\u5b57\u4f53\u57fa\u7840\u77e5\u8bc6<\/h4>\n<p><code>vertical-align<\/code>\u5c5e\u6027\u652f\u6301 top\/baseline\/bottom \u8fd9 3 \u4e2a\u503c\uff0c\u8fd9\u4e2a\u5f88\u591a\u4eba\u77e5\u9053\uff0c\u5b9e\u9645\u4e0a\uff0c<code>ascent<\/code> \u548c <code>descent<\/code> \u4e5f\u662f\u6587\u5b57\u5782\u76f4\u5bf9\u9f50\u4e2d\u975e\u5e38\u91cd\u8981\u7684\u4e24\u6761\u7ebf\u3002<\/p>\n<p>\u53c2\u89c1\u4e0b\u9762\u7684\u793a\u610f\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202203\/2022-03-21_213748.png\" width=\"480\" height=\"203\" alt=\"\u5b57\u4f53\u4e2d\u7684\u5404\u79cd\u7ebf\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u8868\u793a\u82f1\u6587\u5b57\u6bcd\uff08\u5305\u62ec\u5927\u5199\uff09\u56fe\u5f62\u7684\u4e0a\u4e0b\u8fb9\u7f18\u7ebf\u4f4d\u7f6e\u3002<\/p>\n<p>\u5982\u679c\u5927\u5bb6\u5bf9 SVG \u5b57\u4f53\u4e86\u89e3\uff0c\u5c31\u53ef\u4ee5\u770b\u5230\u5176\u5b57\u4f53\u9762\u7684\u63cf\u8ff0\u4e2d\u6709 <code>ascent<\/code> \u548c <code>descent<\/code> \u8fd9\u4e24\u9879\uff0c\u5982\u4e0b\u622a\u56fe\u793a\u610f\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202203\/2022-03-21_214402.png\" width=\"414\" height=\"284\" alt=\"ascent\u548cdescent\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<pre>&lt;font-face \r\n  font-family=\"ZxxHeiTi\"  \r\n  font-weight=\"400\"   \r\n  font-stretch=\"normal\"    \r\n  units-per-em=\"1000\"\r\n  ascent=\"1240\" \r\n  descent=\"-334\" \r\n\/&gt;<\/pre>\n<p><code>ascent-override<\/code>\u548c<code>descent-override<\/code>\u5c5e\u6027\u5c31\u662f\u7528\u6765\u91cd\u7f6e\u5b57\u4f53\u5185\u90e8\u7684 <code>ascent<\/code> \u548c <code>descent<\/code> \u7684\u3002<\/p>\n<h4>line-gap-override\u4f5c\u7528<\/h4>\n<p>\u5982\u679c\u5927\u5bb6\u8ba4\u771f\u8bfb\u8fc7 \u300aCSS\u4e16\u754c\u300b\uff0c\u5c31\u5e94\u8be5\u77e5\u9053 <code>line-height:normal<\/code> \u8fd9\u4e2a CSS \u58f0\u660e\u5f88\u6709\u6545\u4e8b\uff0c\u5f53\u884c\u9ad8\u4e3a normal \u7684\u65f6\u5019\uff0c\u6700\u7ec8\u7684\u884c\u9ad8\u5927\u5c0f\u662f\u7531\u5b57\u4f53\u51b3\u5b9a\u7684\u3002<\/p>\n<p>\u4f8b\u5982\u4e0b\u9762\u6211\u624b\u673a\u62cd\u7684\u7167\u7247\uff0c\u5176\u4e2d\u5fae\u8f6f\u96c5\u9ed1\u5b57\u4f53\u548c\u5b8b\u4f53\u4e0b\u7684\u884c\u9ad8\u8ba1\u7b97\u503c\u5c31\u662f\u4e0d\u4e00\u6837\u7684\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202203\/book-line-height.jpg\" width=\"640\" height=\"252\" alt=\"normal\u4e0d\u540c\u5b57\u4f53\u4e0b\u7684\u884c\u9ad8\u8ba1\u7b97\u503c\" class=\"alignnone size-medium\" \/><\/p>\n<p><code>line-gap-override<\/code> \u5c5e\u6027\u7684\u4f5c\u7528\u662f\u91cd\u7f6e\u8fd9\u4e2a\u5b57\u4f53\u5185\u90e8\u8bbe\u5b9a\u7684\u884c\u95f4\u9699\uff08\u53ef\u4ee5\u8fd1\u4f3c\u7406\u89e3\u4e3a\u884c\u9ad8\uff09\u3002<\/p>\n<h3>\u4e8c\u3001\u529f\u80fd\u6f14\u793a<\/h3>\n<p>\u4e0a\u9762\u4ecb\u7ecd\u4e86\u51e0\u4e2a\u5c5e\u6027\u7684\u4f5c\u7528\uff0c\u4e0b\u9762\u770b\u4e0b\u771f\u5b9e\u7684\u8868\u73b0\u6548\u679c\uff0c\u8fd9\u51e0\u4e2a CSS \u5c5e\u6027\u90fd\u9700\u8981\u5728 <code>@font-face<\/code> \u58f0\u660e\u4e2d\u624d\u6709\u6548\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>@font-face {\r\n    font-family: ascentFont;\r\n    src: local('PingFang SC'),\r\n         local('Microsoft Yahei');\r\n    ascent-override: 100%;\r\n    descent-override: 0%;\r\n    line-gap-override: 80%;\r\n}<\/pre>\n<p>\u4e3a\u4e86\u65b9\u4fbf\u5927\u5bb6\u76f4\u89c2\u4f53\u9a8c\u6548\u679c\uff0c\u6211\u4e13\u95e8\u505a\u4e2a\u4e2a\u6f14\u793a\u9875\u9762\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/202203\/ascent-descent-line-gap-override-demo.php\" rel=\"noopener\" target=\"_blank\">CSS ascent-override descent-override line-gap-override\u57fa\u672c\u6548\u679cdemo<\/a><\/p>\n<p>\u5404\u4e2a\u5c5e\u6027\u8868\u73b0\u5982\u4e0b GIF \u622a\u5c4f\u793a\u610f\uff1a<\/p>\n<p><strong>1. ascent-override<\/strong><\/p>\n<p>ascent \u662f\u8bbe\u7f6e\u4e0a\u60ac\u7ebf\u7684\u4f4d\u7f6e\uff0c\u9ed8\u8ba4\u662f 100%\uff0c\u8303\u56f4\u4ece 0%-\u221e\uff0c\u503c\u8d8a\u5927\uff0c\u6587\u5b57\u8d8a\u4e0b\u6c89\uff0c\u8fd9\u4e2a\u5f88\u597d\u7406\u89e3\uff0c\u4e0a\u60ac\u7ebf\u7684\u4f4d\u7f6e\u5927\u4e86\u4e4b\u540e\uff0c\u6587\u5b57\u7684\u6587\u5b57\u81ea\u7136\u5c31\u9760\u4e0b\u4e86\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202203\/accent-override.gif\" width=\"297\" height=\"211\" alt=\"\u4e0a\u60ac\u7ebf\u4f4d\u7f6e\u91cd\u7f6e\u793a\u610f\u56fe\" class=\"alignnone size-medium\" \/><\/p>\n<p><strong>2. descent-override<\/strong><\/p>\n<p>descent \u662f\u8bbe\u7f6e\u4e0b\u60ac\u7ebf\u4f4d\u7f6e\uff0c\u7531\u4e8e\u4e0d\u652f\u6301\u8d1f\u503c\uff0c\u4e14\u4e00\u822c\u5b57\u4f53\u5185\u90e8\u7684 descent \u90fd\u662f\u8d1f\u503c\uff0c\u56e0\u6b64\uff0c\u521d\u59cb\u503c\u53ef\u4ee5\u770b\u6210\u662f 0%\uff0c\u503c\u8d8a\u5927\uff0c\u6587\u5b57\u7684\u4f4d\u7f6e\u8d8a\u9ad8\u3002\u4f8b\u5982\u4e0b\u9762 GIF\uff0c\u6240\u4ee5\u6ed1\u6746\u79fb\u52a8\u5230\u53f3\u4fa7\uff0c\u6587\u5b57\u6240\u5728\u7684\u5782\u76f4\u4f4d\u7f6e\u660e\u663e\u53d8\u9ad8\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202203\/descent-override.gif\" width=\"297\" height=\"211\" alt=\"\u4e0b\u60ac\u7ebf\u6548\u679c\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p><strong>3. line-gap-override<\/strong><\/p>\n<p><code>line-gap-override<\/code> \u8bbe\u7f6e\u8981\u60f3\u751f\u6548\uff0c\u5219\u5bf9\u5e94\u5b57\u4f53\u6240\u5728\u7684 <code>lien-height<\/code> \u5c5e\u6027\u503c\u5fc5\u987b\u662f <code>normal<\/code>\uff0c\u65e0\u8bba\u662f\u6570\u503c\uff0c\u957f\u5ea6\u503c\u8fd8\u662f\u767e\u5206\u6bd4\u503c\u90fd\u4f1a\u8ba9 <code>line-gap-override<\/code> \u5c5e\u6027\u6ca1\u6709\u6548\u679c\u3002<\/p>\n<p><code>line-gap-override<\/code> \u4e0d\u652f\u6301\u8d1f\u503c\uff0c\u56e0\u6b64\uff0c\u53ea\u80fd\u8ba9\u884c\u9ad8\u53d8\u9ad8\uff0c\u800c\u4e0d\u80fd\u51cf\u5c11\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202203\/line-gap-override.gif\" width=\"297\" height=\"267\" alt=\"\u884c\u95f4\u9699\u91cd\u7f6e\" class=\"alignnone size-medium\" \/><\/p>\n<h3>\u4e09\u3001\u5e94\u7528\u573a\u666f<\/h3>\n<p>\u5728\u67d0\u4e9b Android \u8bbe\u5907\u4e0b\uff0c\u6216\u8005\u4f7f\u7528\u67d0\u4e9b\u81ea\u5b9a\u4e49\u5b57\u4f53\u6216\u56fe\u6807\u7684\u65f6\u5019\uff0c\u6587\u5b57\u6216\u8005\u56fe\u5f62\u603b\u662f\u6ca1\u6cd5\u5782\u76f4\u5c45\u4e2d\uff0c\u65e0\u8bba\u662f Flex \u5e03\u5c40\u7684 <code>align-items:center<\/code> \uff0c\u8fd8\u662f <code>line-height<\/code> \u8bbe\u7f6e\u90fd\u4e0d\u884c\uff0c\u5219\u591a\u534a\u662f\u8fd9\u4e2a\u5b57\u4f53\u5185\u90e8\u7684\u4e0a\u60ac\u7ebf\u6216\u8005\u4e0b\u60ac\u7ebf\u4f4d\u7f6e\u4e0d\u592a\u5bf9\u3002<\/p>\n<p>\u6b64\u65f6\u53ef\u4ee5\u4f7f\u7528\u672c\u6587\u63d0\u4f9b\u7684\u8fd9\u51e0\u4e2a\u5c5e\u6027\u8fdb\u884c\u91cd\u5b9a\u4e49\u8fdb\u884c\u4fee\u590d\u3002<\/p>\n<p>\u6211\u60f3\uff0c\u8fd9\u5c31\u662f\u8fd9\u51e0\u4e2a CSS \u5c5e\u6027\u8bbe\u8ba1\u7684\u610f\u4e49\u6240\u5728\u3002<\/p>\n<p>\u4e0d\u8fc7\uff0c\u6709\u70b9\u9057\u61be\u7684\u662f\uff0c\u76ee\u524d Safari \u6d4f\u89c8\u5668\u8fd8\u6ca1\u6709\u5bf9\u5176\u8fdb\u884c\u652f\u6301\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202203\/2022-03-21_231547.png\" width=\"561\" height=\"233\" alt=\"\u517c\u5bb9\u6027\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<h4>\u5728 JS \u4e2d\u4f7f\u7528<\/h4>\n<p>\u53e6\u5916\uff0c<code>ascent-override<\/code>\u3001<code>descent-override<\/code>\u7b49\u5c5e\u6027\u4e5f\u662f\u53ef\u4ee5\u5728 JavaScript \u4ee3\u7801\u4e2d\u4f7f\u7528\u7684\uff0c\u4f7f\u7528\u5168\u5c40\u7684 <code>FontFace<\/code> \u5bf9\u8c61\u63a5\u53e3\uff0c\u4e0b\u9762\u662f\u4e00\u6bb5\u4ee3\u7801\u793a\u610f\uff0c\u9002\u5408\u4e0d\u592a\u559c\u6b22 CSS \u7684\u5f00\u53d1\u5c0f\u4f19\u4f34\uff1a<\/p>\n<pre>let fontFace = new FontFace('Roboto', 'url(.\/roboto.woff2)', {\r\n  'descentOverride': '90%'\r\n});\r\nconsole.log(fontFace.descentOverride); \/\/ 90%\r\nfontFace.descentOverride = 'normal';\r\nconsole.log(fontFace.descentOverride); \/\/ 'normal'<\/pre>\n<h3>\u56db\u3001\u7ed3\u5c3e\u7684\u7d6e\u53e8<\/h3>\n<p>\u6700\u8fd1\u5c0f\u533a\u88ab\u5c01\u4e86\uff0c\u4e00\u5207\u4ece\u4e25\uff0c\u5f88\u4e45\u6ca1\u51fa\u95e8\u4e86\uff0c\u5176\u5b9e\u6211\u89c9\u5f97\u5427\u2026\u2026<\/p>\n<p>\u5199\u4e86\u5f88\u591a\uff0c\u53c8\u5220\u4e86\uff0c\u7b97\u4e86\u2026\u2026\u597d\u597d\u5199\u4ee3\u7801\u3002<\/p>\n<p>\u4eca\u5929\u770b\u65b0\u95fb\uff0c\u53d1\u751f\u4e86\u7a7a\u96be\uff0c\u6574\u4e2a\u4eba\u5fc3\u60c5\u90fd\u4e0d\u597d\u4e86\uff0c\u521a\u5f00\u59cb\u5237\u5230\u7684\u65f6\u5019\u8fd8\u6ca1\u786e\u8ba4\uff0c\u5e0c\u671b\u662f\u5c0f\u6545\u969c\uff0c\u6ca1\u60f3\u5230\u2026\u2026<\/p>\n<p>\u2026\u2026\u53c8\u5220\u4e86\uff0c\u7b97\u4e86\u2026\u2026\u597d\u597d\u5199\u4ee3\u7801\u3002<\/p>\n<p>\u505a\u597d\u81ea\u5df1\uff0c\u53d1\u5149\u53d1\u70ed\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/emtion\/emoji\/2600.svg\" width=\"20\" height=\"20\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u6b22\u8fce\u5206\u4eab\uff0c\u52ff\u5168\u6587\u8f6c\u8f7d\uff0c\u5982\u679c\u5b9e\u5728\u559c\u6b22\uff0c\u53ef\u6536\u85cf\uff0c\u6c38\u4e0d\u8fc7\u671f\uff0c\u4e14\u4f1a\u53ca\u65f6\u66f4\u65b0\u77e5\u8bc6\u70b9\u53ca\u4fee\u6b63\u9519\u8bef\uff0c\u9605\u8bfb\u4f53\u9a8c\u4e5f\u66f4\u597d\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10319\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=10319<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202203\/flay-font-cover.png\" width=\"160\" height=\"100\" alt=\"\u7834\u8327\u6210\u8776\" class=\"alignright size-medium\" \/><\/p>\n<p>@font-face \u81ea\u5b9a\u4e49\u5b57\u4f53\u7684\u53c8\u65b0\u589e\u4e86\u4e00\u4e9b\u65b0\u5c5e\u6027\uff0c\u8fdb\u6765\u770b\u770b\u90fd\u662f\u5e72\u561b\u7528\u7684\u5427\uff0c\u8bf4\u4e0d\u5b9a\u53ef\u4ee5\u89e3\u51b3\u4f60\u7684\u8d85\u7ea7\u68d8\u624b\u7684\u96be\u9898\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[1819,1820,1581,416,655,417,1578,1087],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/10319"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=10319"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/10319\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=10319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=10319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=10319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}