UNIT 10 • STAGE 5 OF 7

Modal HTML & CSS

Build the popout window that will appear when a visitor clicks a dancer card

UNIT
STEP 1

What Is a Modal?

A modal is an overlay window that appears on top of the page. When a visitor clicks a dancer card, the rest of the page dims and a box floats in the center with information about that dance tradition. Clicking the close button, or anywhere outside the box, makes it disappear.

The modal is made of two HTML pieces nested inside each other:

  • #modal-overlay, a fixed-position div that covers the entire screen. It has a dark semi-transparent background. It starts hidden with display: none. JavaScript will change it to display: flex to reveal it.
  • .modal, the box that sits centered inside the overlay. It holds the title, Tribal Nation label, and description text. JavaScript will fill these in when a card is clicked.

JavaScript comes in Stage 6

This stage builds the HTML and CSS for the modal. It will exist in the page but nothing will open it yet, that wiring happens in Stage 6. You can still preview the modal by temporarily changing display: none to display: flex in your CSS.

STEP 2

Add data-dance Attributes

Each dancer card needs to tell JavaScript which dance it represents. You do this with a data attribute, a custom attribute you can add to any HTML element using the data- prefix followed by any name you choose.

Find each .dancer-card div in your HTML and add data-dance="..." to it. Use the exact keys shown below, JavaScript will use these to look up the right content:

👉 Add data-dance to each .dancer-card opening tag: <div class="dancer-card" data-dance="jingle-dress">
<div class="dancer-card" data-dance="fancy-shawl">
<div class="dancer-card" data-dance="womens-traditional">
<div class="dancer-card" data-dance="grass-dance">
<div class="dancer-card" data-dance="mens-traditional">
<div class="dancer-card" data-dance="mens-fancy">

These values are the keys JavaScript will use to look up which dance was clicked. The spelling and hyphens must match exactly, you will define those same keys in the data object in Stage 6.

STEP 3

Add Modal CSS

Add these six rules just above </style>:

👉 Add just above </style>: #modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal {
  background: #1a1237;
  color: white;
  max-width: 580px;
  width: 100%;
  border-radius: 16px;
  padding: 48px 40px;
  position: relative;
  max-height: 85vh;
  overflow-y: auto;
}

#modal-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.5);
  font-size: 2rem;
  cursor: pointer;
  transition: color 0.2s;
}

#modal-title {
  font-size: 2.25rem;
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

#modal-nation {
  font-size: 0.8125rem;
  color: #d4a853;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
  margin-bottom: 24px;
}

#modal-description {
  font-size: 1rem;
  line-height: 1.9;
  color: rgba(255, 255, 255, 0.85);
}
STEP 4

Add Modal HTML

Add this HTML just before </body>. The title, nation, and description are empty, JavaScript will fill them in when a card is clicked:

👉 Add just before </body>: <div id="modal-overlay">
  <div class="modal">
    <button id="modal-close">&times;</button>
    <h2 id="modal-title"></h2>
    <p id="modal-nation"></p>
    <p id="modal-description"></p>
  </div>
</div>

Preview the modal

To see how it looks, temporarily change display: none to display: flex in your #modal-overlay CSS. The box will appear over the page. Change it back to none when you are done, Stage 6 will wire up the real open/close behavior.

STEP 5

Why These Styles?

  • position: fixed on #modal-overlay, removes the element from the page flow entirely and pins it relative to the browser window. It stays in place even if the page is scrolled.
  • inset: 0, sets top, right, bottom, and left all to 0 in one shorthand. Combined with position: fixed, this stretches the overlay to cover the entire viewport.
  • z-index: 100, stacks the overlay above everything else on the page. The dancer cards use z-index: 1 and z-index: 2. A value of 100 guarantees the modal sits on top.
  • display: none, the overlay starts hidden. JavaScript will change this to display: flex when a card is clicked. The align-items and justify-content values are already in the rule, ready to center the box the moment it becomes flex.
  • max-width: 580px and width: 100% on .modal, the box grows to fill the screen on small devices but never exceeds 580 pixels on larger ones.
  • max-height: 85vh; overflow-y: auto, on short screens, the modal box will not overflow the window. Instead it becomes scrollable so the full description is always reachable.
  • data-dance attributes, custom attributes you invent using the data- prefix. They do not affect how the HTML renders. They are a message to JavaScript: "this card belongs to this dance key." Stage 6 will read them with getAttribute('data-dance').

Stage 5 Complete!

The modal structure is in place. In Stage 6 you will write the JavaScript that reads data-dance, looks up the right content, fills the modal fields, and opens it when a card is clicked.

Code Editor
Live Preview