/styles/global.css
body {
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
background-color: black;
color: white;
font-size: 18px;
}
a {
color: inherit;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
display: block;
}
body {
line-height: 1;
}
ol,
ul {
list-style: none;
}
blockquote,
q {
quotes: none;
}
blockquote:before,
blockquote:after,
q:before,
q:after {
content: "";
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
/styles/navigation.module.css
.nav {
background-color: red;
padding: 50px 100px;
}
.list {
display: flex;
}
/components/navigation.tsx
"use client";
import Link from "next/link";
import {usePathname} from "next/navigation";
import styles from "../styles/navigation.module.css";
export default function Navigation () {
const path = usePathname();
return (
<nav className={styles.nav}>
<ul className={styles.list}>
<li>
<Link href="/">Home</Link>{path === "/" ? "π₯" : ""}
</li>
<li>
<Link href="/about-us">About us</Link>{path === "/about-us" ? "π₯" : ""}
</li>
</ul>
</nav>
);
}
κΈλ‘λ² CSS νμΌ μμ±:
μ ν리μΌμ΄μ
μ 체μ μ μ©ν μ€νμΌμ μ μνκΈ° μν΄ styles ν΄λ λ΄μ global.css νμΌ μμ±.
μμ:
/* styles/global.css */
body {
background-color: black;
font-family: system-ui;
color: white;
margin: 0;
padding: 0;
}
a {
text-decoration: none;
}
κΈλ‘λ² CSS νμΌ μ μ©:
layout.tsx νμΌμ μ΅μλ¨μ global.cssλ₯Ό importνμ¬ μ 체 μ ν리μΌμ΄μ
μ κΈλ‘λ² μ€νμΌ μ μ©.
// app/layout.tsx
import './styles/global.css';
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
μ»΄ν¬λνΈλ³ CSS λͺ¨λ νμΌ μμ±:
κ° μ»΄ν¬λνΈμ κ³ μ ν μ€νμΌμ μ μ©νκΈ° μν΄ .module.css νμΌ μμ±.
μμ: Navigation μ»΄ν¬λνΈλ₯Ό μν navigation.module.css νμΌ μμ±.
/* components/navigation.module.css */
.nav {
background-color: red;
padding: 50px 100px;
}
.list {
display: flex;
list-style: none;
}
.item {
margin-right: 20px;
}
.link {
color: white;
text-decoration: underline;
}
CSS λͺ¨λ μ¬μ©:
μ»΄ν¬λνΈ νμΌμμ CSS λͺ¨λμ importνκ³ , classNameμ λμ μΌλ‘ ν λΉ.
// components/Navigation.tsx
import styles from './navigation.module.css';
export default function Navigation() {
return (
<nav className={styles.nav}>
<ul className={styles.list}>
<li className={styles.item}><a href="#" className={styles.link}>Home</a></li>
<li className={styles.item}><a href="#" className={styles.link}>About Us</a></li>
</ul>
</nav>
);
}