Mengapa kami terpaksa menggunakan font yang dibundel dengan material-ui?
Apakah ada cara untuk menghapus atau mengkonfigurasi ini?
Sebenarnya, setelah 6 jam mencari online, menggali kode lib dan menebak-nebak secara acak, kesimpulan yang saya dapatkan: ITU MUNGKIN! :D
/public/fonts/fonts.css
, yang mendefinisikan @font-faces:@font-face {
font-family: 'inglobal';
font-weight: normal;
font-style: normal;
src: url('./inglobal.ttf');
}
tambahkan <link rel="stylesheet" href="%PUBLIC_URL%/fonts/fonts.css">
ke /public/index.html's head
Hore!
4/b. Jika, karena alasan apa pun, tetap tidak berfungsi, ubah ekstensi font menjadi .css (juga di src: url('./OperatorMono.css')
)
tautkan font google di index.html Anda
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,500,700&display=swap" rel="stylesheet">
Tambahkan gaya tubuh Anda
/* Styles */
body {
margin: 0 auto;
font-family: 'Montserrat';
}
beberapa perubahan di app.js
import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles';
const theme = createMuiTheme({
typography: {
fontFamily: [
'Montserrat'
].join(','),
},
})
/public/index.html
bekerja untuk saya :)
Sebenarnya, setelah 6 jam mencari online, menggali kode lib dan menebak-nebak secara acak, kesimpulan yang saya dapatkan: ITU MUNGKIN! :D
- buat direktori /fonts di /publik
- buat
/public/fonts/fonts.css
, yang mendefinisikan @font-faces:@font-face { font-family: 'inglobal'; font-weight: normal; font-style: normal; src: url('./inglobal.ttf'); }
- tambahkan
<link rel="stylesheet" href="%PUBLIC_URL%/fonts/fonts.css">
ke /public/index.html's head- Hore!
4/b. Jika, karena alasan apa pun, tetap tidak berfungsi, ubah ekstensi font menjadi .css (juga di
src: url('./OperatorMono.css')
)
Ini pekerjaan!! Terima kasih.
Ikuti 2 langkah ini untuk mengubah font default:
Di sini saya mengubah font default menjadi "Open Sans"
Impor Google Font di index.html Anda
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap" rel="stylesheet"/>
Lakukan perubahan ini di index.js
import { ThemeProvider } from '@material-ui/styles';
import { CssBaseline } from '@material-ui/core';
import { createMuiTheme } from '@material-ui/core';
const theme = createMuiTheme({ typography: { fontFamily: [ 'Open Sans' ].join(','), }, })
ReactDOM.render(
<ThemeProvider theme={theme}>
<CssBaseline />
<App />
</ThemeProvider>,
document.getElementById('root')
);
_Terkadang urutan penting selama konfigurasi. Sebagai praktik yang baik, selalu tentukan tipografi di tingkat atas selama konfigurasi di createMuiTheme _
Setelah tema konfigurasi tidak mendapatkan font-family
// Create a theme instance.
const theme = createMuiTheme({
palette: {
primary: {
main: "#2991d6",
},
secondary: {
main: "#19857b",
},
error: {
main: red.A400,
},
background: {
default: "#fff",
},
}, typography: {
fontFamily: "VarelaRound,sans-serif",
},
overrides: {
MuiCssBaseline: {
"@global": {
"@font-face": [varelaRound],
},
},
},
});
Note:
In this case Material UI using Roboto as the default font
// Create a theme instance.
const theme = createMuiTheme({
typography: {
fontFamily: "VarelaRound,sans-serif",
},
palette: {
primary: {
main: "#2991d6",
},
secondary: {
main: "#19857b",
},
error: {
main: red.A400,
},
background: {
default: "#fff",
},
},
overrides: {
MuiCssBaseline: {
"@global": {
"@font-face": [varelaRound],
},
},
},
});
Saya hanya mengubah urutan dan semuanya bekerja dengan baik.
Komentar yang paling membantu
Sebenarnya, setelah 6 jam mencari online, menggali kode lib dan menebak-nebak secara acak, kesimpulan yang saya dapatkan: ITU MUNGKIN! :D
/public/fonts/fonts.css
, yang mendefinisikan @font-faces:tambahkan
<link rel="stylesheet" href="%PUBLIC_URL%/fonts/fonts.css">
ke /public/index.html's headHore!
4/b. Jika, karena alasan apa pun, tetap tidak berfungsi, ubah ekstensi font menjadi .css (juga di
src: url('./OperatorMono.css')
)