Lesson 1: Introduction to CSS – Dressing Up Your HTML


Lesson1

Lesson 1: Introduction to CSS – Dressing Up Your HTML

Overview

Welcome, future web design legend! In this first lesson, we’ll dive into CSS (Cascading Style Sheets)—the magic that transforms your plain, awkward HTML into the web equivalent of a catwalk model. Think of HTML as the skeleton, and CSS as the fabulous outfit that makes your website the talk of the town.

By the end of this lesson, you’ll know how to link CSS to your HTML, set up a project folder, and host it using Caddy (the server, not the car). Plus, you’ll master the fine art of text editors—Vim, VSCode, or the trusty old Nano. Ready to make your HTML look less like a plain pizza and more like a gourmet dish? Let’s do this!


Step 1: Set Up Your Project Folder

First things first: time to put some order in your life (well, at least in your project folder). Here’s how to create a clean space for your soon-to-be stylish HTML and CSS:

  1. Open a terminal (don’t worry, no magic spells required).

  2. Navigate to where you want to store your project (your digital wardrobe):

    cd ~/Documents
    
  3. Create a new folder to hold your brilliance:

    mkdir my-css-project
    
  4. Enter the newly created folder like a boss:

    cd my-css-project
    
  5. Create two files: one for your HTML and one for your CSS (think of them as your website’s shirt and pants):

    touch index.html styles.css
    

Now you have a folder setup like a neat closet:

my-css-project/
    ├── index.html
    └── styles.css

Step 2: Pick Your Editor (The Real Fashion Designer)

Here’s where you get to choose your weapon of choice for coding. It’s like choosing your tool for a cooking show—go fancy with VSCode, classic with Vim, or keep it simple with Nano. Either way, let’s make sure your code looks sharp.

Using Vim (The Old-School Ninja):

  • Open your index.html:

    vim index.html
    
  • Press i for insert mode, write your HTML, then hit ESC and type :wq to save and quit like a coding ninja.

  • Do the same for styles.css:

    vim styles.css
    

Using VSCode (The Cool Kid on the Block):

  • Open your project folder:
    code .
    
  • Now, use your mouse like a 21st-century pro and open index.html and styles.css from the sidebar. Simple, sleek, stylish.

Using Nano (The Minimalist):

  • Open index.html:
    nano index.html
    
  • After writing, hit CTRL+O to save and CTRL+X to exit. No frills, just you and your code—minimalism at its finest.

Step 3: Write Your HTML and CSS (Time to Dress Up Your Site)

Time to add some flavor to your otherwise naked HTML page. You know, give it some personality, like putting sunglasses on a turtle—it’s instantly cooler.

In index.html, throw this in:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My First CSS Page</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <h1>Welcome to My CSS World!</h1>
    <p>This is my first page with custom styles using CSS. Look at me, I’m stylish now!</p>
</body>
</html>

Look at that! Your HTML is polite enough to introduce itself now. Let’s make it stand out more with some killer CSS.

In styles.css, add this fashion statement:

body {
    background-color: #f0f0f0;
    font-family: 'Arial', sans-serif;
}

h1 {
    color: #3498db;
    font-size: 48px;
}

p {
    color: #2c3e50;
    font-size: 20px;
}

Now, your webpage has gone from “I just woke up” to “Ready for the runway.” The gray background is classy, the blue heading is bold, and the paragraph looks sharp in a dark gray suit.


Step 4: Serve Your Project with Caddy (Let’s Go Live!)

Let’s get that masterpiece online… well, at least on your local network. Enter Caddy—the easiest way to turn your code into a website without needing a degree in server management.

  1. Install Caddy if you haven’t yet: Check out the Caddy Installation Guide and follow the instructions (don’t worry, it’s easier than IKEA instructions, we promise).

  2. Serve Your Website with Caddy: Forget about complex configuration files. Just run this:

    caddy file-server --listen :8080
    

    It’s like turning on a light switch: your files are now being served on port 8080.

  3. Open the Page in Your Browser: Go to your browser and type:

    http://localhost:8080
    

    Boom! Your stylish webpage is now strutting its stuff.

Quick Tip: When Your Browser Acts Like a Diva

Sometimes, your browser likes to hold onto old styles like an outdated wardrobe. Even after you update your CSS, it might insist on showing the old look—like wearing bell-bottom jeans in 2024.

To force it to refresh its style sense, hit Ctrl + F5 (or Cmd + Shift + R on Mac). It’s like telling your browser, “Stop being stubborn, show me the real style!” If your site looks the same even after saving and refreshing, just give Ctrl + F5 a try—it’s like a fashion intervention for your webpage.


Step 5: Edit, Refresh, and Repeat (The Life of a Designer)

Now that you’ve got your site up, you can continue tweaking and refining your look (because fashion is never finished). Make changes to your CSS or HTML and just refresh your browser to see the results.

Here’s what you can do next:

  • Change the background color to something more “you”:

    body {
        background-color: #fff7e6;
    }
    
  • Play with the fonts:

    p {
        font-family: 'Comic Sans MS', sans-serif; /* If you're feeling adventurous */
    }
    
  • Make the heading even bolder:

    h1 {
        font-size: 64px;
    }
    

After making changes, save your file and refresh the page in your browser. Watch your site evolve from stylish to runway-ready.


Conclusion

Congratulations, fashion-forward coder! You’ve not only set up your first HTML and CSS project, but you’ve also learned to use Vim, VSCode, or Nano like a pro and served your project with Caddy. Your website is now dressed to impress.

In the next lesson, we’ll explore CSS selectors and specificity, which is like learning which fabrics and colors work best together to make your website a true masterpiece. Stay tuned—you’re about to get even more stylish.


See also