Global styles
The first thing we will do is create global styles. These are styles that apply site-wide. They should be added to the root component of your theme.
We'll change the font to be sans-serif throughout our site. To do this let's import the <Global> component and the css function from Frontity into our root component file.
<Global> and css, as well as styled which we will look at in the next lesson, are exported by the Emotion library. Frontity integrates Emotion so that you can import these from Frontity.
1
// File: /packages/my-first-theme/src/components/index.js
2
3
// ...
4
import { connect, Global, css } from "frontity"
5
6
const Root = ({ state }) => {
7
const data = state.source.get(state.router.link)
8
9
return (
10
<>
11
<Global
12
styles={css`
13
html {
14
font-family: system-ui, Verdana, Arial, sans-serif;
15
}
16
`}
17
/>
18
{/* ... */}
19
</>
20
)
21
}
Copied!
The <Global> component has an attribute, styles, which in turn takes a css function as it's value.
The css function takes as it's argument a tagged template literal, which in this case consists of a string of standard CSS contained within backticks. You can put any CSS here that you want to be applied site wide.
When you save the file you should notice that the fonts on your site have now changed automatically to be sans-serif.
Next we'll look at the power and flexibility that styled components give us.
Check you're on the right track by comparing your changes with the ones in this commit.
Last modified 8mo ago
Copy link