CiTi · Computer Coding · Year One · Unit 3

Dropdown Navigation Menus on MySite

Student Handout

Base Code

Start from W3Schools: Dropdown Menu in a Navigation Bar ↗

Anatomy of the Dropdown

In your own words, what does each part do?

The wrapper: <div class="dropdown"> The button: <button class="dropbtn"> The content: <div class="dropdown-content"> Explain this rule, reading right to left: .dropdown:hover .dropdown-content { display: block; }

My Dropdown Plan

Nav item that becomes a dropdown
Pages inside it (2–3)

Checklist before you move on: CSS is in css/style.css (not a <style> block) · Font Awesome <link> is in every page’s head · nav is pasted into every page · no href="#" left.

Break It On Purpose

Make one change at a time. Predict first, test, then undo it before the next one.

1. Delete overflow:hidden from .navbar

I predict
What happened
Why

2. Add position:relative; to .dropdown

I predict
What happened
Why

3. Move the .navbar a rule to the bottom of the stylesheet

I predict
What happened
Why

4. Change .dropdown:hover .dropbtn to .dropbtn:hover

I predict
What happened
Why

Mobile Test

Right-click your page and choose Inspect. In the top-left corner of the Inspect panel, click the mobile device icon (a small phone and tablet). Pick a phone from the Dimensions menu at the top of the page, then try your menu.

What went wrong at phone size?

Now add this to the bottom of css/style.css, upload, and re-test:

.dropdown:focus-within .dropdown-content { display: block; } @media (max-width: 600px) { .navbar a, .dropdown, .dropdown .dropbtn { float: none; display: block; width: 100%; text-align: left; } .dropdown-content { display: block; position: static; box-shadow: none; } .dropdown-content a { padding-left: 32px; } }
What changed? Test at phone width AND by pressing Tab on a laptop.

Success Criteria Check-In

Check each one when you feel confident you can do it.

Exit Ticket

Give one reason a hover dropdown doesn’t work well on a phone, and explain what your media query does about it