使用本地自定义字体,实现思路参考如下:
@font-face { font-family: 'HarmonyOS Sans'; src: url('./font/HarmonyOS_Sans_SC_Regular.ttf'); } .harmonyos-sans { font-family: 'HarmonyOS Sans', sans-serif; }
完整示例参考如下:
import { webview } from '@kit.ArkWeb'; @Entry @Component struct WebComponent { controller: webview.WebviewController = new webview.WebviewController(); build() { Column() { Web({ src: $rawfile('Index.html'), controller: this.controller }) .fileAccess(true) .javaScriptAccess(true) .domStorageAccess(true) .onlineImageAccess(true) .geolocationAccess(false) } } }
<!DOCTYPE html>
<html lang="en-gb">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>自定义字体</title>
<style>
body {
font-size: 20px;
}
@font-face {
font-family: 'HarmonyOS Sans';
src: url('./font/HarmonyOS_Sans_SC_Regular.ttf');
}
.harmonyos-sans {
font-family: 'HarmonyOS Sans', sans-serif;
}
</style>
</head>
<body>
<div class="harmonyos-sans">Sans字体:Innation in china</div>
</body>
</html>