The simplest way to add style is inline styles
<p>first paragraph</p>
<p style={{ color: 'red' }}>second paragraph</p>
if the style depends on the data coming from an api request, then inline style is the best choice
<div style={{
backgroundImage: `url("${imageUrl}")`,
}} />
A CSS Module is a CSS file in which all class names are scoped locally by default.
This allows you to use the same CSS class name in different files without worrying about collisions.
Next.js supports CSS Modules using the [name].module.css
file naming convention.
file components/Button.module.css
.btn {
color: white;
border-radius: 4px;
font-size: large;
}
.primary {
composes: btn;
background-color: green;
}
.danger {
composes: btn;
background-color: red;
}
file components/Button.js
import styles from './Button.module.css';
export default () => (
<button
type="button"
className={styles.primary}
>
click here
</button>
);
styled-jsx is another way to add a component-level CSS.
you can skip scoping entirely by adding global.
export default () => (
<>
<h2>title</h2>
<p>paragraph</p>
<style jsx>{`
h2 {
font-family: Arial;
}
p {
color: blue;
}
`}</style>
<style global jsx>{`
body {
background: gray;
}
`}</style>
</>
);
allows you to do things like:
pages/_app.js
import Navbar from "../components/navbar";
import '../css/style.css';
const App = ({ Component, pageProps }) => (
<>
<Navbar />
<Component {...pageProps} />
</>
);
export default App;
importing css files is only allowed inside
pages/_app.js
to prevent collisions
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing