Tujuan Belajar
Setelah pelajaran ini, kamu akan bisa:
- Menggabungkan semua konsep CSS (box model, flexbox, warna, hover, responsive) dalam satu proyek
- Mengubah halaman HTML polos menjadi halaman yang terlihat profesional
- Melihat transformasi nyata dari HTML mentah ke halaman yang berdesain
Materi Singkat
Ini adalah momen yang kamu tunggu-tunggu! Di Modul HTML kamu membuat tentang-saya.html yang tampilannya seperti dokumen teks biasa. Sekarang kita akan mengubahnya menjadi halaman web yang sesungguhnya — dengan warna, tipografi, layout, dan interaksi yang indah.
Yang Akan Kita Tambahkan
Satu file CSS komprehensif yang mencakup:
- Reset & base styles — fondasi yang bersih
- Tipografi — font, ukuran, warna teks yang nyaman dibaca
- Header & navigasi — responsive, profesional
- Hero section — background gambar dengan overlay
- Section-section dengan kartu dan spacing yang baik
- Tombol dan badge — dengan hover state yang mulus
- Tabel yang mudah dibaca (zebra striping)
- Form yang terasa modern
- Footer yang rapi
- Responsive — tampil baik di HP dan desktop
Filosofi Desain
- Konsistensi — pakai satu set warna dan spacing yang konsisten
- Readability — teks harus nyaman dibaca (kontras tinggi, line-height cukup)
- Minimalis — kurangi noise, fokus pada konten
- Interaktif — feedback visual saat hover dan fokus
Contoh Kode
Ini adalah style.css lengkap untuk halaman profil:
/* ── RESET & BASE ────────────────────────────── */
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
:root {
--color-accent: #2563eb;
--color-accent-hover: #1d4ed8;
--color-foreground: #1a1a1a;
--color-muted: #6b7280;
--color-border: #e5e7eb;
--color-surface: #f7f7f7;
}
html {
scroll-behavior: smooth;
}
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
color: var(--color-foreground);
background-color: var(--color-surface);
line-height: 1.7;
}
img {
max-width: 100%;
height: auto;
}
/* ── TYPOGRAPHY ──────────────────────────────── */
h1 { font-size: 1.875rem; font-weight: 700; }
h2 { font-size: 1.375rem; font-weight: 600; }
h3 { font-size: 1.125rem; font-weight: 600; }
a {
color: var(--color-accent);
text-decoration: none;
transition: color 0.2s ease;
}
a:hover { color: var(--color-accent-hover); text-decoration: underline; }
/* ── LAYOUT ──────────────────────────────────── */
.container {
max-width: 720px;
margin: 0 auto;
padding: 0 16px;
}
/* ── HERO ────────────────────────────────────── */
.hero {
position: relative;
background-image: url('https://picsum.photos/1200/400?random=42');
background-size: cover;
background-position: center;
padding: 80px 16px;
text-align: center;
color: white;
}
.hero::before {
content: '';
position: absolute;
inset: 0;
background-color: rgba(0, 0, 0, 0.55);
}
.hero-content {
position: relative;
z-index: 1;
}
.hero h1 {
font-size: 2.25rem;
margin-bottom: 8px;
}
.hero p {
font-size: 1rem;
opacity: 0.85;
}
/* ── HEADER ──────────────────────────────────── */
header {
background: white;
border-bottom: 1px solid var(--color-border);
padding: 16px;
position: sticky;
top: 0;
z-index: 100;
}
.header-inner {
max-width: 720px;
margin: 0 auto;
display: flex;
justify-content: space-between;
align-items: center;
}
.header-name {
font-weight: 700;
font-size: 1.125rem;
color: var(--color-foreground);
}
nav ul {
list-style: none;
display: flex;
gap: 4px;
}
nav ul li a {
display: inline-block;
padding: 6px 12px;
font-size: 0.875rem;
color: var(--color-muted);
border-radius: 4px;
transition: color 0.2s, background-color 0.2s;
}
nav ul li a:hover {
color: var(--color-accent);
background-color: #eff6ff;
text-decoration: none;
}
/* ── MAIN CONTENT ────────────────────────────── */
main {
padding: 24px 16px;
max-width: 720px;
margin: 0 auto;
}
/* ── SECTION / KARTU ─────────────────────────── */
section {
background: white;
border: 1px solid var(--color-border);
border-radius: 8px;
padding: 24px;
margin-bottom: 20px;
transition: box-shadow 0.2s ease;
}
section:hover {
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.07);
}
section h2 {
color: var(--color-foreground);
margin-bottom: 16px;
padding-bottom: 10px;
border-bottom: 2px solid var(--color-accent);
}
/* ── PROFIL LAYOUT ───────────────────────────── */
.profil-layout {
display: flex;
flex-direction: column;
gap: 20px;
align-items: center;
text-align: center;
}
.profil-foto {
width: 120px;
height: 120px;
border-radius: 50%;
border: 4px solid var(--color-accent);
object-fit: cover;
flex-shrink: 0;
}
/* ── LIST ────────────────────────────────────── */
ul, ol {
padding-left: 20px;
}
li {
margin-bottom: 6px;
}
/* ── BADGE ───────────────────────────────────── */
.badge {
display: inline-block;
padding: 3px 12px;
border-radius: 9999px;
background-color: #dbeafe;
color: var(--color-accent);
font-size: 0.8rem;
font-weight: 600;
margin: 3px 4px 3px 0;
}
.skill-grid {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 12px;
}
/* ── TOMBOL ──────────────────────────────────── */
.btn {
display: inline-block;
padding: 10px 20px;
border-radius: 6px;
font-weight: 600;
font-size: 0.875rem;
text-decoration: none;
cursor: pointer;
border: none;
margin-right: 8px;
margin-bottom: 8px;
transition: background-color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}
.btn-primary {
background-color: var(--color-accent);
color: white;
}
.btn-primary:hover {
background-color: var(--color-accent-hover);
box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
text-decoration: none;
}
.btn-primary:active { transform: scale(0.97); }
.btn-secondary {
background-color: transparent;
border: 2px solid var(--color-accent);
color: var(--color-accent);
}
.btn-secondary:hover {
background-color: #eff6ff;
text-decoration: none;
}
/* ── TABEL ───────────────────────────────────── */
table {
width: 100%;
border-collapse: collapse;
font-size: 0.9rem;
}
th {
background-color: var(--color-accent);
color: white;
text-align: left;
padding: 10px 14px;
}
td {
padding: 10px 14px;
border-bottom: 1px solid var(--color-border);
}
tr:nth-child(even) td { background-color: #f9fafb; }
tr:hover td { background-color: #eff6ff; transition: background-color 0.15s; }
/* ── FORM ────────────────────────────────────── */
form p { margin-bottom: 16px; }
label {
display: block;
margin-bottom: 4px;
font-size: 0.875rem;
font-weight: 600;
color: var(--color-foreground);
}
input[type="text"],
input[type="email"],
textarea,
select {
width: 100%;
padding: 10px 14px;
border: 1px solid var(--color-border);
border-radius: 6px;
font-size: 1rem;
font-family: inherit;
outline: none;
transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
input:focus,
textarea:focus,
select:focus {
border-color: var(--color-accent);
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
/* ── FOOTER ──────────────────────────────────── */
footer {
background: #1a1a1a;
color: rgba(255, 255, 255, 0.7);
padding: 32px 16px;
text-align: center;
font-size: 0.875rem;
}
footer a {
color: rgba(255, 255, 255, 0.9);
transition: color 0.2s;
}
footer a:hover {
color: white;
text-decoration: underline;
}
/* ── RESPONSIVE ──────────────────────────────── */
@media (min-width: 640px) {
.profil-layout {
flex-direction: row;
align-items: flex-start;
text-align: left;
}
}
@media (min-width: 1024px) {
main { padding: 32px 0; }
section { padding: 32px; }
}Tugas: Selesaikan Proyek CSS-mu!
Ambil tentang-saya.html yang kamu buat di Modul HTML dan:
- Buat
style.cssbaru (atau salin template di atas sebagai titik mulai) - Hubungkan dengan
<link rel="stylesheet" href="style.css" />di<head> - Sesuaikan CSS dengan konten aslimu — warna bisa kamu ganti sesukamu
- Tambahkan class yang diperlukan ke HTML (
container,profil-layout,btn,badge, dll.)
Checklist:
- [ ] Reset (
box-sizing: border-box, dll.) - [ ] CSS custom properties (variabel) untuk warna
- [ ] Header sticky dengan navigasi
- [ ] Hero section dengan background gambar
- [ ] Section sebagai kartu (border, border-radius, shadow)
- [ ] Flexbox untuk layout profil (foto + bio)
- [ ] Badge untuk skill
- [ ] Tombol primary & secondary
- [ ] Tabel dengan zebra striping dan hover
- [ ] Form dengan focus state yang jelas
- [ ] Footer dengan background gelap
- [ ] Responsive (minimal satu breakpoint di 640px)