Material-ui: تغيير / استخدام الخط المخصص

تم إنشاؤها على ٧ أبريل ٢٠١٦  ·  7تعليقات  ·  مصدر: mui-org/material-ui

لماذا نضطر إلى استخدام الخطوط المجمعة مع واجهة المستخدم المادية؟

هل هناك طريقة لإزالة أو تكوين هذا؟

التعليق الأكثر فائدة

في الواقع ، بعد 6 ساعات من البحث على الإنترنت ، والحفر في كود lib والتخمين العشوائي ، توصلت إلى الاستنتاج التالي: إنه ممكن!

  1. إنشاء / دليل الخطوط في / public
  2. أنشئ /public/fonts/fonts.css ، الذي يعرّف @ font-faces:
@font-face {
  font-family: 'inglobal';
  font-weight: normal;
  font-style: normal;
  src: url('./inglobal.ttf');
}
  1. أضف <link rel="stylesheet" href="%PUBLIC_URL%/fonts/fonts.css"> إلى رأس /public/index.html

  2. يا هلا!

4 / ب. إذا لم تنجح ، لأي سبب من الأسباب ، فغيّر امتدادات الخطوط إلى .css (أيضًا بسعر src: url('./OperatorMono.css') )

ال 7 كومينتر

في الواقع ، بعد 6 ساعات من البحث على الإنترنت ، والحفر في كود lib والتخمين العشوائي ، توصلت إلى الاستنتاج التالي: إنه ممكن!

  1. إنشاء / دليل الخطوط في / public
  2. أنشئ /public/fonts/fonts.css ، الذي يعرّف @ font-faces:
@font-face {
  font-family: 'inglobal';
  font-weight: normal;
  font-style: normal;
  src: url('./inglobal.ttf');
}
  1. أضف <link rel="stylesheet" href="%PUBLIC_URL%/fonts/fonts.css"> إلى رأس /public/index.html

  2. يا هلا!

4 / ب. إذا لم تنجح ، لأي سبب من الأسباب ، فغيّر امتدادات الخطوط إلى .css (أيضًا بسعر src: url('./OperatorMono.css') )

  1. ربط خطوط google في index.html الخاص بك
    <link href="https://fonts.googleapis.com/css?family=Montserrat:400,500,700&display=swap" rel="stylesheet">

  2. أضف في أسلوب جسمك
    /* Styles */ body { margin: 0 auto; font-family: 'Montserrat'; }

  3. تغييرات قليلة في app.js
    import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles';

const theme = createMuiTheme({ typography: { fontFamily: [ 'Montserrat' ].join(','), }, })

/public/index.html


عملت لي :)

في الواقع ، بعد 6 ساعات من البحث على الإنترنت ، والحفر في كود lib والتخمين العشوائي ، توصلت إلى الاستنتاج التالي: إنه ممكن!

  1. إنشاء / دليل الخطوط في / public
  2. أنشئ /public/fonts/fonts.css ، الذي يعرّف @ font-faces:
@font-face {
  font-family: 'inglobal';
  font-weight: normal;
  font-style: normal;
  src: url('./inglobal.ttf');
}
  1. أضف <link rel="stylesheet" href="%PUBLIC_URL%/fonts/fonts.css"> إلى رأس /public/index.html
  2. يا هلا!

4 / ب. إذا لم تنجح ، لأي سبب من الأسباب ، فغيّر امتدادات الخطوط إلى .css (أيضًا بسعر src: url('./OperatorMono.css') )

إنه عمل !! شكرا لك.

اتبع هاتين الخطوتين لتغيير الخط الافتراضي:

أنا هنا أقوم بتغيير الخط الافتراضي إلى "Open Sans"

  1. استيراد خطوط Google في index.html الخاص بك
    <link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap" rel="stylesheet"/>

  2. قم بإجراء هذه التغييرات في 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')
);

_أحيانًا يكون التسلسل مهمًا أثناء التكوين. كممارسة جيدة ، حدد الطباعة دائمًا في المستوى الأعلى أثناء التكوين في createMuiTheme _

القضية:

بعد سمة التكوين لم يتم الحصول على عائلة الخطوط

// 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],
      },
    },
  },
});

أنا فقط أغير التسلسل وكل شيء يعمل بشكل جيد.

هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات

القضايا ذات الصلة

reflog picture reflog  ·  3تعليقات

rbozan picture rbozan  ·  3تعليقات

newoga picture newoga  ·  3تعليقات

activatedgeek picture activatedgeek  ·  3تعليقات

pola88 picture pola88  ·  3تعليقات