我正在 Chrome 95 中加載一個 Hello World html 檔案,其中宣告了從 Google 字體加載的 @font-face。字體正確加載,我可以在“網路”選項卡中進行驗證,但由于某種原因,我的 div 呈現為時間。
我究竟做錯了什么?
<html>
<div style='font-family:OpenSans-Regular;'>
Hello World!
</div>
</html>
<style>
@font-face {
font-family: OpenSans-Regular;
font-style: normal;
font-weight: 400;
font-stretch: 100%;
font-display: swap;
src: url(https://fonts.gstatic.com/s/opensans/v27/memvYaGs126MiZpBA-UvWbX2vVnXBbObj2OVTSKmu0SC55K5gw.woff2) format('woff2');
}
</style>
uj5u.com熱心網友回復:
從Google 字體檔案 中,您應該使用<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Font Name">而不是直接撰寫它們。
你的<style>元素在錯誤的地方,<body>你的 HTML中沒有元素。
<html>
<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open Sans">
<style>
* {
font-family: "Open Sans";
}
</style>
</head>
<body>
<div style='font-family:Open Sans'>
Hello World!
</div>
</body>
</html>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/364857.html
