Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to connect and use a 3 custom fonts in a Nuxt3 project with your module and tailwind? #332

Open
CuberHuber opened this issue Oct 11, 2024 · 2 comments

Comments

@CuberHuber
Copy link

No description provided.

@danielroe
Copy link
Member

Would you provide more information? What are you trying?

@CuberHuber
Copy link
Author

I found a solution to this problem.

I have 3 custom fonts called MyFont-Regular, MyFont-Light, MyFont-Bold in repo/public/fonts/. And I want to use them as tailwindcss classes.

  1. You need to update nuxt config
//  nuxt.config.ts

module.exports = {
    // other configs
    theme: {
        extend: {
            fontFamily: {
                span: ['MyFont', 'sans-serif'],
                sans: ['MyFont', 'sans-serif'],
                display: ['MyFont', 'sans-serif'],
                custom: ['MyFont'],
            },
            fontWeight: {
                light: 300,
                normal: 400,
                bold: 700,
            },
        },
        utilities: {
            fontCustom: {
                fontFamily: 'MyFont',
            },
            fontLight: {
                fontWeight: 'light',
            },
            fontNormal: {
                fontWeight: 'normal',
            },
            fontBold: {
                fontWeight: 'bold',
            },
        },
    },
}
  1. You need to create an app.css file in the project dir and add the following lines
// app.css

@tailwind;
@tailwind base;
@tailwind components;
@tailwind utilities;

    @font-face {
        font-family: 'MyFont';
        src: url('~public/fonts/MyFont-Light.otf');
        font-weight: 300;
        font-style: normal;
        font-display: swap;
    }

    @font-face {
        font-family: 'MyFont';
        src: url('~public/fonts/MyFont-Regular.otf');
        font-weight: 400;
        font-style: normal;
        font-display: swap;
    }

    @font-face {
        font-family: 'MyFont';
        src: url('~public/fonts/MyFont-Bold.otf');
        font-weight: 700;
        font-style: normal;
        font-display: swap;
    }

Example of using MyFont

<template>
    <span class="text-md text-cell-dark font-bold">{{ text }}</span>
</template>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants