What is the best way to set all headers in my prose class to a specific font?
The following is what I have, but does not seem to be working:
theme: {
typography: {
DEFAULT: {
css: {
h1: {
fontFamily: ['Bebas Neue', 'sans-serif'],
},
h2: {
fontFamily: ['Bebas Neue', 'sans-serif'],
},
h3: {
fontFamily: ['Bebas Neue', 'sans-serif'],
},
h4: {
fontFamily: ['Bebas Neue', 'sans-serif'],
},
h5: {
fontFamily: ['Bebas Neue', 'sans-serif'],
},
...
Also is there a less verbose way to set all headers at once?
You can use prose-headings variant or any other element modifier you need. Prose headings will target h1, h2, h3, h4, th
<div class="prose prose-headings:text-red-400">
// Content
</div>
DEMO
Related
Tailwind has started acting up on my latest project and after hours of debugging I can't figure out what's happening.
When I have this:
<div class='fixed bottom-0 right-6 sm:relative sm:block'>
The div is always fixed, regardless of the screen size. In this:
<div class='hidden sm:flex'>
OR
<div class='hidden sm:block'>
The div is always hidden, regardless of the screen size.
However, for borders and text-colors responsiveness works. Is that expected behavior?
This is my tailwind.config.js
module.exports = {
purge: [
'./resources/**/*.blade.php',
'./resources/**/*.js',
'./resources/**/*.vue',
],
darkMode: false, // or 'media' or 'class'
theme: {
fontFamily: {
'mont': 'Montserrat',
'open': 'Open Sans',
'roboto': 'Roboto',
'lato': 'Lato',
},
extend: {
colors: {
'xmas-red': '#b71a3b',
'xmas-dark-red': '#7e0f12',
'xmas-brown': '#bc6d4c',
'xmas-olive': '#6a7045',
// 'xmas-gray': '#313c33',
'xmas-gray': '#364739',
'xmas-blue': '#072b54'
},
width: {
'124': '60rem',
},
height: {
'100': '36rem'
}
},
},
variants: {
extend: {
opacity: ['disabled'],
backgroundColor: ['disabled'],
borderColor: ['disabled'],
textColor: ['disabled'],
},
},
plugins: [
require('#tailwindcss/forms')
],
}
For example, let's say I want to use the following markdown
# AAAAAAAAAa
BBBBBBB
which would be parsed accordingly such that AAAAAAAAAa is h1 and BBBBBB is <p>, and all of this is enclosed with a prose div in using Tailwind Typography. Under normal circumstances, the two would share the same font defined in tailwind.config.js, and I am wondering how I can change this setting such that the two would have different fonts.
There are examples on the link you provided. Take a look at Customization and Modifiers.
You can directly add property to certain element (h1,h2,h3,p, etc). See example below:
// tailwind.config.js
module.exports = {
theme: {
extend: {
typography: {
DEFAULT: {
css: {
color: '#333',
h1: {
fontFamily: ['Roboto', 'sans-serif'],
},
p: {
fontFamily: ['Montserrat', 'sans-serif'],
},
},
},
}
},
},
plugins: [
require('#tailwindcss/typography'),
// ...
],
}
or you can create your own modifier like this:
// tailwind.config.js
module.exports = {
theme: {
extend: {
typography: {
'3xl': {
css: {
fontSize: '1.875rem',
h1: {
fontSize: '4rem',
fontFamily: ['Montserrat', 'sans-serif'],
},
p: {
fontSize: '1.5rem',
fontFamily: ['Roboto', 'sans-serif'],
},
// ...
},
},
},
}
},
plugins: [
require('#tailwindcss/typography'),
// ...
],
}
A simple demo.
Is below the proper way to inline font declaration in head tag in nuxt.config.js. Trying to follow best practices for font loading strategies from https://web.dev/font-best-practices/. The style tag doesn't seem to be working. Can anyone help?!
link: [
{ rel: 'preconnect', href: 'https://fonts.googleapis.com' },
{ rel: 'dns-prefetch', href: 'https://fonts.gstatic.com' },
{
rel: 'preconnect',
href: 'https://fonts.gstatic.com',
crossorigin: 'anonymous',
},
{
rel: 'stylesheet',
href: 'https://fonts.googleapis.com/css2?family=Inter:wght#200;300;400;700&subset=latin&display=swap',
},
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
],
style: [
{
cssText:
'#font-face { font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segou UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif }',
type: 'text/css',
},
{
cssText:
'body { font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segou UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif }',
type: 'text/css',
},
],
Here is my CSS (flex4.6)
/* CSS file */
#namespace mx "library://ns.adobe.com/flex/mx";
#namespace s "library://ns.adobe.com/flex/spark";
#font-face {
src:url("assets/MyriadWebPro.ttf");
fontFamily: myCFFFont;
embedAsCFF: true;
}
#font-face {
src:url("assets/MyriadWebPro.ttf");
fontFamily: myFontNoCFF;
embedAsCFF: false;
}
mx|Application{
fontFamily: myFontNoCFF;
}
mx|Button {
fontFamily: myFontNoCFF;
}
mx|Label{
fontFamily: myFontNoCFF;
}
s|Application {
fontFamily: myCFFFont;
}
s|FormItem {
fontFamily: myCFFFont;
fontStyle:normal;
fontWeight:normal;
}
global {
fontFamily: myCFFFont;
}
This is ok for labels, buttons etc... except for formitems:
<s:FormItem width="346" label="{lang.msg_enter_nickname}">
These formItem render with not embed fonts.
What do I am doing wrong ?
Regards
I encountered this problem, it's a bug in SDK (https://issues.apache.org/jira/browse/FLEX-26380). I tried to find workaround but didn't. Use mx:FormItem instead spark.
Short example to describe the problem. Set up a usual Flex mobile project with the following files (and OpenSans font).
Main.mxml
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
applicationDPI="160">
<s:layout><s:VerticalLayout/></s:layout>
<fx:Style source="style.css"/>
<s:Label text="Static Label"/>
<s:Button label="Static Button" skinClass="MyButtonSkin"/>
</s:Application>
style.css
#namespace s "library://ns.adobe.com/flex/spark";
#font-face {
src: url("fonts/opensans/OpenSans-Bold.ttf");
fontFamily: OpenSansBoldEmbedded;
embedAsCFF: true;
}
s|Label,
s|Button
{
fontFamily: OpenSansBoldEmbedded;
font-lookup: embeddedCFF;
}
MyButtonSkin.mxml
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark">
<!-- host component -->
<fx:Metadata>
[HostComponent("spark.components.Button")]
</fx:Metadata>
<s:Label id="labelDisplay" />
</s:Skin>
The result is that the simple label is styled with the embedded font, but the label in the button isn't. So it looks like this: http://img813.imageshack.us/img813/44/skinningtest.png
I've tried other CSS properties like color and font-size and it works for both. Only the embedded fonts won't work in Spark skins.
What do I miss to style the label in the button with the embedded font?
Solution
Use the attributes fontWeight and fontStyle at the import (#font-face) and on usage (.OpenSansEmbeddedBold). It's not enough to embed the bold font and use it.
/* Import the different font weights and styles */
#font-face {
src: url("fonts/opensans/OpenSans-Regular.ttf");
fontFamily: OpenSansEmbedded;
}
#font-face {
src: url("fonts/opensans/OpenSans-Bold.ttf");
fontFamily: OpenSansEmbedded;
fontWeight: bold;
}
#font-face {
src: url("fonts/opensans/OpenSans-Italic.ttf");
fontFamily: OpenSansEmbedded;
fontStyle: italic;
}
#font-face {
src: url("fonts/opensans/OpenSans-BoldItalic.ttf");
fontFamily: OpenSansEmbedded;
fontWeight: bold;
fontStyle: italic;
}
/* Register fonts as styleNames for further use */
.OpenSansEmbedded
{
fontFamily: OpenSansEmbedded;
}
.OpenSansEmbeddedBold
{
fontFamily: OpenSansEmbedded;
fontWeight: bold;
}
.OpenSansEmbeddedItalic
{
fontFamily: OpenSansEmbedded;
fontStyle: italic;
}
.OpenSansEmbeddedBoldItalic
{
fontFamily: OpenSansEmbedded;
fontWeight: bold;
fontStyle: italic;
}
Use the defined classes as styleName in your MXML
<s:Label text="Static Label" styleName="OpenSansEmbeddedBold"/>
I don't know exactly why, but try adding fontWeight: normal; in your css and this will help. I came to this conclusion after changing fontFamily to Verdana and seeing that button label was bold.
for the button you should use embedAsCFF: false
#namespace s "library://ns.adobe.com/flex/spark";
#font-face {
src: url("fonts/opensans/OpenSans-Bold.ttf");
fontFamily: OpenSansBoldEmbedded;
embedAsCFF: true;
}
#font-face {
src: url("fonts/opensans/OpenSans-Bold.ttf");
fontFamily: OpenSansBoldEmbeddedForBtn;
embedAsCFF: false;
}
s|Label
{
fontFamily: OpenSansBoldEmbedded;
font-lookup: embeddedCFF;
}
s|Button
{
fontFamily: OpenSansBoldEmbeddedForBtn;
}