HTML - Web Slide Desk

Introduction to Web Slide Deck

Hello there, aspiring web developers! Today, we're going to embark on an exciting journey into the world of HTML and create our very own web slide deck. As your friendly neighborhood computer teacher, I'm thrilled to guide you through this process, even if you've never written a line of code before. So, buckle up and let's dive in!

HTML - Web slide Desk

What is a Web Slide Deck?

Before we start coding, let's understand what we're building. A web slide deck is essentially a presentation that runs in a web browser. It's like PowerPoint, but cooler because you're creating it from scratch using HTML! This means you can access it anywhere, anytime, as long as you have internet access.

Setting Up Our HTML Document

Let's start with the basic structure of our HTML document. Don't worry if this looks intimidating at first – we'll break it down step by step.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Awesome Web Slide Deck</title>
    <style>
        /* We'll add some CSS here later */
    </style>
</head>
<body>
    <!-- Our slides will go here -->
</body>
</html>

Let's break this down:

  • <!DOCTYPE html> tells the browser this is an HTML5 document.
  • <html lang="en"> is the root element of our HTML page, with "en" specifying English language.
  • The <head> section contains meta information about the document.
  • <meta charset="UTF-8"> specifies the character encoding for the document.
  • <meta name="viewport"...> ensures proper rendering on mobile devices.
  • <title> sets the title of our web page.
  • The <style> tag is where we'll add our CSS later.
  • The <body> is where the visible content of our slide deck will go.

Creating Our First Slide

Now, let's create our first slide. We'll use <section> tags to define each slide.

<body>
    <div class="slideshow-container">
        <section class="slide">
            <h1>Welcome to My Web Slide Deck!</h1>
            <p>Created by [Your Name]</p>
        </section>
    </div>
</body>

Here, we've:

  • Added a <div> with class "slideshow-container" to hold all our slides.
  • Created a <section> with class "slide" for our first slide.
  • Added a heading <h1> and a paragraph <p> to our slide.

Adding More Slides

Let's add a couple more slides to our deck:

<div class="slideshow-container">
    <section class="slide">
        <h1>Welcome to My Web Slide Deck!</h1>
        <p>Created by [Your Name]</p>
    </section>

    <section class="slide">
        <h2>What We'll Cover</h2>
        <ul>
            <li>HTML Basics</li>
            <li>CSS Styling</li>
            <li>Simple JavaScript</li>
        </ul>
    </section>

    <section class="slide">
        <h2>Thank You!</h2>
        <p>Any questions?</p>
    </section>
</div>

We've added two more slides, each with different content structures. The second slide uses an unordered list <ul> to display bullet points.

Styling Our Slides with CSS

Now, let's add some style to our slides. We'll put this in the <style> tag in our <head> section:

<style>
    body, html {
        height: 100%;
        margin: 0;
        font-family: Arial, sans-serif;
    }
    .slideshow-container {
        height: 100%;
        display: flex;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
    }
    .slide {
        min-width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        scroll-snap-align: start;
        padding: 20px;
        box-sizing: border-box;
    }
    .slide:nth-child(1) { background-color: #f4f4f4; }
    .slide:nth-child(2) { background-color: #e8e8e8; }
    .slide:nth-child(3) { background-color: #dcdcdc; }
</style>

Let's break down this CSS:

  • We set the body and html to full height and remove default margins.
  • The .slideshow-container uses flexbox for layout and scroll-snap-type for smooth sliding.
  • Each .slide is set to full width and height, with centered content.
  • We use scroll-snap-align to ensure slides snap into place when scrolling.
  • Different background colors are set for each slide using :nth-child.

Adding Navigation Buttons

To make our slide deck more user-friendly, let's add some navigation buttons:

<body>
    <div class="slideshow-container">
        <!-- ... slides here ... -->
    </div>
    <button class="prev" onclick="changeSlide(-1)">❮ Prev</button>
    <button class="next" onclick="changeSlide(1)">Next ❯</button>

    <script>
        function changeSlide(n) {
            const slides = document.querySelectorAll('.slide');
            const currentSlide = document.querySelector('.slide:target') || slides[0];
            let index = Array.from(slides).indexOf(currentSlide);
            index = (index + n + slides.length) % slides.length;
            location.hash = '#' + slides[index].id;
        }
    </script>
</body>

We've added:

  • "Prev" and "Next" buttons with onclick events.
  • A changeSlide function in JavaScript to handle navigation.

Let's style these buttons:

<style>
    /* ... previous styles ... */
    .prev, .next {
        position: fixed;
        top: 50%;
        padding: 10px;
        color: white;
        background-color: rgba(0,0,0,0.5);
        border: none;
        cursor: pointer;
    }
    .prev { left: 10px; }
    .next { right: 10px; }
</style>

Final Touches

To make our navigation work smoothly, we need to add IDs to our slides:

<section id="slide1" class="slide">
    <h1>Welcome to My Web Slide Deck!</h1>
    <p>Created by [Your Name]</p>
</section>

<section id="slide2" class="slide">
    <h2>What We'll Cover</h2>
    <ul>
        <li>HTML Basics</li>
        <li>CSS Styling</li>
        <li>Simple JavaScript</li>
    </ul>
</section>

<section id="slide3" class="slide">
    <h2>Thank You!</h2>
    <p>Any questions?</p>
</section>

Conclusion

Congratulations! You've just created your very own web slide deck using HTML, CSS, and a touch of JavaScript. This is just the beginning – you can now experiment with different styles, add more interactive elements, or even incorporate animations.

Remember, web development is all about practice and creativity. Don't be afraid to tweak the code and see what happens. Who knows? You might discover something amazing!

Happy coding, future web wizards!

Methods Table

Method Description
document.querySelectorAll() Selects all elements that match a CSS selector
document.querySelector() Selects the first element that matches a CSS selector
Array.from() Creates a new Array instance from an array-like object
indexOf() Returns the first index at which a given element can be found in the array
location.hash Gets/sets the part of the URL that follows the # symbol

Credits: Image by storyset