Reputation: 181
I'm following the Tailwind CSS documentation, but after I rebuild the CSS file, the font class does not appear in the generated file for some reason. So, I went to Google Fonts and copied the import and pasted it into a CSS file I want to compile, and it looks like this:
styles.css
@tailwind base;
@tailwind components;
@import url('https://fonts.googleapis.com/css2?family=DotGothic16&family=Lato:wght@300;400;700;900&family=Roboto:wght@400;500;700&family=Rubik:wght@400;500;700&display=swap');
@tailwind utilities;
Then I went to the Tailwind config file and added fontFamily.
tailwind.config.js
module.exports = {
purge: [],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {
},
fontFamily: {
'body': ['Lato'],
}
},
variants: {
extend: {},
},
plugins: [],
}
At last, I used this command to recompile
npx tailwindcss build styles.css -o output.css
If I try to apply the class "font-body," it doesn't work, and that makes sense since the class is not in output.css
Upvotes: 0
Views: 1142
Reputation: 413
Few mistakes that I see in your code are:
fontFamily:{
'Lato':{'Lato', 'sans-serif'}
}
You should use the css rules to specify as mentioned in google fonts.
Your import statement has 3 fonts. If you are only using Lato, remove the others and configure them properly for your own better understanding.
We should generally rebuild our css file, if you have done major changes. Rebuilding is not necessary in v.2. Using :
npm build YOUR_FILE.css
and restarting dev server should work. No need of creating another output file.
Upvotes: 1