✦ Web Development with Django Style your web page

L3 · Concept 05 · Web Fundamentals

Make Your HTML
Look Like Yours.

Continue the local <code>my-project-hub</code> project. CSS gives the HTML structure you built a clear visual design that adapts to smaller screens.

Learning goalConnect a stylesheet and read a CSS rule as selector → property → value → browser result. Then use the box model, simple layouts, and DevTools to make deliberate changes.
01 Edit style.css02 Check in your browser03 Inspect with DevTools

Learning as a guest

Learning as a guest? Save your progress!

Create a free account to learn with Sloby AI, check your understanding, and track your progress.

The entire platform is free throughout 2026. Foundations stays free forever.

Sloby's Tip — Why are we learning CSS?

Python and Django remain our focus for building web applications. CSS controls how those applications look, so focus on readable, usable pages and on investigating styling problems rather than memorizing every property.

HTML describes content, while CSS controls how it looks. Link style.css in the head of index.html. Read each rule as: select these elements → change this property → use this value → the browser renders the result.

h1 { color: #1d4ed8; }
.site-title { font-size: 2rem; }

A CSS rule has a selector, a property, and a value. In .project-card { padding: 1rem; }, .project-card selects matching elements, padding names what changes, and 1rem is the value. The browser applies that rule and renders inner space around the content.

Link an external stylesheet once inside the head of index.html: <link rel="stylesheet" href="style.css">. The browser then reads both files.

↳

Keep source files separate: Save changes in style.css, then refresh the browser unless Live Server refreshes it for you. A temporary edit in DevTools does not automatically save to your file.

Element selectors and class selectors
<article class="project-card">
  ...
</article>

h1 { color: #1d4ed8; }
.project-card { padding: 1rem; }

body, nav, and h1 are element selectors. In HTML, class="project-card" names a reusable group; in CSS, .project-card selects elements with that class. The dot means “select this class.”

Typography and color
body {
  font-family: Arial, sans-serif;
  line-height: 1.6;
  background: #f4f7fb;
}
a { color: #1d4ed8; }

Use color, background, font-family, font-size, and line-height to make content readable before adding decoration.

Read one element from the inside out: content → padding → border → margin. Padding is space inside the border; margin is space outside it between neighboring elements.

.project-card { padding: 1rem; margin: 1rem 0; border: 1px solid #cbd5e1; }
The box model
.card {
  box-sizing: border-box;
  padding: 1rem;
  margin: 1rem 0;
  border: 1px solid #cbd5e1;
  border-radius: 0.75rem;
}

Read outward from content: padding creates space inside the border, the border is the edge, and margin creates space outside it between neighboring elements.

Margin — outer space
Border — edge
Padding — inner space
Content

Navigation links such as Home, About, and Projects naturally follow normal HTML flow. When you want them arranged as one navigation row, make their nav parent a flex container with display: flex. Its direct link children can then be arranged along a main direction: gap adds space between them, justify-content distributes them along that main direction, and align-items lines them up across it.

nav { display: flex; gap: 1rem; justify-content: space-between; align-items: center; }
Build one Flexbox navigation rule step by step
nav { display: flex; }
nav { gap: 1rem; }
nav { justify-content: space-between; }
nav { align-items: center; }

Start with display: flex: nav becomes the flex container and its direct links can form a row. Add gap: 1rem for space between links. Then justify-content: space-between spreads them along the main axis, while align-items: center aligns them on the cross axis. The complete rule combines these decisions; the same HTML and stylesheet remain in use on a small screen.

↕ Cross axis — align-items lines links up↔ Main axis — justify-content distributes links

Imagine several project cards: two in one row and two below them. Flexbox is useful when you are mainly arranging items along one direction; Grid is a useful beginner model when you want rows and columns. First make .projects-grid a grid container with display: grid, then use grid-template-columns: repeat(2, 1fr) for two equal columns. Here 1fr means one equal share of the available space, and gap adds space between cards.

.projects-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

The same HTML and CSS file can produce a different layout when the viewport—the visible width of the browser page—changes. A matching @media rule applies only for that viewport; @media (max-width: 768px) means 768 pixels wide or narrower, not a new page. DevTools are browser tools that let you inspect the displayed HTML and CSS, then temporarily experiment before saving a useful correction in style.css.

@media (max-width: 768px) { nav { flex-direction: column; } }
DevTools: inspect, experiment, then save
.project-card {
  padding: 16px;
}

DevTools are tools built into your browser for viewing the displayed page. Right-click a project card and choose Inspect; the browser opens DevTools and selects that card in Elements, which shows the HTML. In Styles, find .project-card and temporarily change padding: 16px to padding: 32px. The inner space grows immediately. Computed shows the final value the browser is using. Refresh to remove the experiment, or copy the value you like into style.css, save it, and refresh. DevTools is for inspection and experimentation, not a replacement for your editor.

Read and debug CSS one deliberate step at a time

  1. Find the HTML elementStart with the exact element you want to style in index.html or DevTools.
  2. Find its selectorDecide whether an element selector such as h1 or a class selector such as .project-card targets it.
  3. Name one property and valueAsk what you are changing and what value you are giving it: for example, padding: 1rem.
  4. Confirm the stylesheet connectionCheck that style.css is linked from index.html and that both files are saved.
  5. Use DevTools as evidenceInspect the element and see whether the expected rule appears in Styles or another value is being applied.
  6. Keep experiments temporary until savedChange one small rule in DevTools to test an idea, then copy a useful change into style.css. Refreshing removes DevTools-only changes.

Common CSS first steps

  • DevTools changed my source fileDevTools is temporary. Put the final fix in style.css, save it, and refresh the page.
  • The stylesheet is not connectedCheck that the link is in head and that href="style.css" matches the saved file name.
  • The class selector does not match HTMLA rule such as .project-card works only when the HTML has class="project-card". Check spelling exactly.
  • Forgetting the dot for a class selectorproject-card selects an HTML element with that name; .project-card selects a class.
  • Confusing padding and marginPadding creates space inside the border around content. Margin creates space outside the border between elements.
  • Inspecting the wrong elementUse Inspect to select the element you intended before deciding that a rule is missing or ignored.
  • Treating a media query as a separate pageA media query changes which rules apply for a viewport. It does not create a second mobile HTML page.

Guided Lab — Style My Project Hub

Do this in VS Code

Continue with the <code>my-project-hub</code> folder from Concept 04. Keep the HTML you built; each step adds a small CSS improvement you can check immediately in the browser.

Your existing local project
my-project-hub/
├── index.html
└── style.css

Open both files in VS Code. You may use a browser file address or optional Live Server from Concept 04; neither Django nor a Python server is needed.

Eight small styling steps

  1. Connect the stylesheetCreate style.css beside index.html. Keep the existing HTML. Inside head, add the link below the existing meta tags. Put the CSS below into style.css, save both files, and refresh. The page background should change.
    <link rel="stylesheet" href="style.css">
    
    /* style.css */
    body { background: #f4f7fb; }
  2. Start with selectorsOpen index.html and add class="site-title" to your existing h1. Keep its text. In style.css, add these rules below the existing body rule, save, and refresh. The title should become blue and larger.
    h1 { color: #1d4ed8; }
    .site-title { font-size: 2rem; }
  3. Improve color and typographyKeep every previous rule. In style.css, extend the body rule and add the link rule below it. Save and refresh; text should be easier to read and links should have a clear color.
    body {
      font-family: Arial, sans-serif;
      line-height: 1.6;
      color: #1f2937;
    }
    a { color: #1d4ed8; }
  4. See the box modelIn index.html, add class="project-card" to the existing Projects section. Add this rule to style.css; do not remove earlier rules. Save and refresh. You should see a bordered section with space inside it and separation around it.
    .project-card {
      box-sizing: border-box;
      padding: 1rem;
      margin: 1rem 0;
      border: 1px solid #cbd5e1;
      border-radius: 0.75rem;
      background: #ffffff;
    }
  5. Make project cardsKeep the Projects section. In its list, add class="project-card" to each existing li. Then replace the section-level card rule with the rule below in style.css. Save and refresh; each project should now look like its own card.
    .project-card {
      list-style: none;
      padding: 1rem;
      margin: 0.75rem 0;
      border: 1px solid #cbd5e1;
      border-radius: 0.75rem;
      background: #ffffff;
    }
  6. Arrange navigation with FlexboxKeep the existing nav and its links from Concept 04. Add this rule to style.css, save, and refresh. The navigation links should appear in a flexible row with visible space between them.
    nav {
      display: flex;
      gap: 1rem;
      justify-content: space-between;
      align-items: center;
    }
  7. Make the layout responsiveKeep all previous CSS. Add this media rule at the end of style.css. Narrow the browser window or use Device Toolbar in DevTools. On a smaller screen, navigation and cards should stack instead of crowding the row.
    @media (max-width: 768px) {
      nav { flex-direction: column; }
      .project-card { margin: 0.5rem 0; }
    }

    One page, two useful layouts

    Desktop — navigation has room to stay in a row
    HomeAboutProjects
    Project cardsProject cards
    Mobile — navigation stacks to protect readable space
    HomeAboutProjects
    Project cardsProject cards

    This mirrors your @media (max-width: 768px) rule. Resize the browser or open Device Toolbar to compare both layouts.

  8. Inspect and fix one CSS mistakeFirst, right-click a correctly styled project card in the browser and choose Inspect. DevTools opens with that element selected: Elements shows its HTML, while Styles shows its CSS rules. In Styles, temporarily change padding: 16px to padding: 32px and watch the inner space grow; refresh to undo that experiment. Then change .project-card to the incorrect .projects-card in style.css, save, and observe that the cards lose their styling. Inspect a card again and use Styles and Computed to see why no matching rule applies. Restore the correct selector in style.css, save, and refresh. Changes made only in DevTools are temporary.
↳

Browser check: style.css → saved → browser refresh small screen → navigation stacks The exact colors are your choice. Confirm that the stylesheet loads, cards have inner padding and outer spacing, and the page remains readable on a narrow screen.

When CSS does not look right

  • Nothing changesCheck that the <code>link</code> is inside <code>head</code>, <code>href="style.css"</code> matches the file name, both files are saved, and the browser was refreshed.
  • A card rule does not applyCheck that the class in <code>index.html</code> exactly matches the selector in <code>style.css</code>, including the dot before a class selector.
  • The small-screen layout did not changeMake the browser narrower than 768 pixels or use Device Toolbar. Check that the <code>@media</code> rule is at the end of the stylesheet and has matching braces.
↳

Next, you will connect the visual frontend to the server-side responsibilities that Django will handle.

Which property creates space inside a card, between its border and its text?

Compare the inside and outside of the box model.

.card {
  border: 1px solid #cbd5e1;
  padding: 16px;
  margin: 24px 0;
}
Choose the output
You don't need to memorize every CSS selector or property. If you can find a rule, understand what it does, and adapt it to your page, you've achieved the goal of this lesson.

Build confidence independently

Make My Project Hub Your Own

Use the CSS you understand to give your existing project a personal visual direction.

Your goalChange a color palette, typography, or card appearance; keep navigation readable; then use DevTools to inspect one element and confirm that the final rule is saved in style.css.
my-project-hub/
├── index.html
└── style.css

Open index.html and style.css in VS Code

Progressive hints
  • Change one CSS rule at a time and refresh the browser.
  • Use a class when several cards should share a style.
  • Use DevTools to inspect the result, then save the final change in style.css.

Ask Sloby for one guiding CSS question. Check My Code is not a CSS validator, so inspect the real result in your browser and DevTools.

Sloby, the Python AI Tutor mascot

Your learning mentor

Sign in to ask Sloby

Create a free account or sign in to get AI guidance while you learn.

Sign in to check your understanding

Create a free account or sign in to receive AI feedback and save your learning progress.

Python AI Tutor · Learn by understanding, not just by running code.