ionic change default font

后端 未结 6 1075
-上瘾入骨i
-上瘾入骨i 2021-02-12 11:52

I know this question is asked and answered before in the links below. I want to change the default font without having to add to every css.

Things I have tried:

相关标签:
6条回答
  • 2021-02-12 12:33

    For Ionic 2: Download the fonts from fonts.google.com and paste it in your assets folder. Now in your scss file do the following:

    @font-face {
    font-family: MyFont;
    src: url("../assets/fonts/Lato-Regular.ttf");
    }
    
    body, span, button, h1, h2, h3, h4, h5, h6, p, ion-item, ion-title {
    font-family: 'MyFont' !important;
    }
    
    0 讨论(0)
  • 2021-02-12 12:36

    The correct solution for Ionic 2 should be to change the $font-family-base variable and its friends. That's the way Ionic is made to do it. It gives you more control (like having different fonts per platform), and it avoids the !important keyword, which is always a good thing.

    Using Ionic 3.3, go to your variables.scss and find the section "Shared variables". Add these lines:

    $font-family-base: 'MyFont';
    $font-family-ios-base: 'MyFont';
    $font-family-md-base: 'MyFont';
    $font-family-wp-base: 'MyFont';
    
    0 讨论(0)
  • 2021-02-12 12:36

    You don't want to replace the icon font by the way, so you should use the CSS3 not() property

    For example, in app.scss :

      @import url(https://fonts.googleapis.com/css?family=Varela+Round);
    
      *:not(ion-icon) {
        font-family: 'Varela Round', sans-serif!important;
      }
    
    0 讨论(0)
  • 2021-02-12 12:40

    You can simply include your icons as svg format.

    Here's a list with all the latest ionicons: https://github.com/Orlandster1998/ionicons-svg

    0 讨论(0)
  • 2021-02-12 12:46

    Import all the font files in to your app.

    Example:

    @font-face {
        font-family: 'Lato-Light';
        src: url('../fonts/Lato-Light.eot') format('embedded-opentype'), url('../fonts/Lato-Light.woff') format('woff'), url('../fonts/Lato-Light.ttf') format('truetype');
        font-weight: normal;
        font-style: normal;
    }
    

    If you want this font in entire app ,Just give like this

    * {
        font-family: 'Lato-Light' !important;
    }
    

    If you have any doubt.Please let me know.Thanks

    0 讨论(0)
  • 2021-02-12 12:51

    For Ionic 4

    There are global variables that are shared across components. --ion-font-family is one of them. Add this in property under :root in variables.scss:

      :root {
          --ion-font-family: 'MyFont';
      }
    

    Ionic 4 Docs: Advanced Theming Documentation

    0 讨论(0)
提交回复
热议问题