I have set the font-family in GlobalStyle. However I want to use another font-family and additional another font-style in one component. It somehow does not work to set it like below.
const GlobalStyle = createGlobalStyle`
body {
font-family: Montserrat;
...
}
`;
const App = () => {
return (
<ThemeProvider theme={theme}>
<GlobalStyle />
<BrowserRouter>
...
</BrowserRouter>
</ThemeProvider>
);
};
and
const Text = styled.p`
font-style: "italic";
font-family: "Arial";
...
`;
The Result is the following
<p font-style="italic" font-family="Arial" class="sc-gtsrHT imMzcY">
But actually the font is still Montserrat and the style normal.
How can I overwrite global style?
3
Answers
In JSX, kebab case for attributes is forbidden.
You should instead use camel case
Also, the word
class
is reserved (because JSX is a javascript format with extra features for template rendering, but it is still javascript). To add a css class to an html element, the word to use isclassName
I think the problem is that you are using the "p" tag instead of the "Text" tag you created, you need to use
<Text> <Text/>
instead<p> </p>
.should not be an italic string
CodeSandbox