Sticky Definition Lists
Recently, I discovered the 30 Seconds of Code website, and their CSS examples are truly impressive! I was particularly captivated by their "floating section headers" using definition lists. This elegantly demonstrates the power and versatility of <dl></dl>
, <dt></dt>
, and <dd></dd>
elements.
Consider this simple HTML:
<div> <dl> <dt>A</dt> <dd>Algeria</dd> <dd>Angola</dd> <dt>B</dt> <dd>Benin</dd> <dd>Botswana</dd> <dd>Burkina Faso</dd> <dd>Burundi</dd> <dt>C</dt> <dd>Cabo Verde</dd> <dd>Cameroon</dd> <dd>Central African Republic</dd> <dd>Chad</dd> <dd>Comoros</dd> <dd>Congo, Democratic Republic of the</dd> <dd>Congo, Republic of the</dd> <dd>Cote d'Ivoire</dd> <dt>D</dt> <dd>Djibouti</dd> <dt>E</dt> <dd>Egypt</dd> <dd>Equatorial Guinea</dd> <dd>Eritrea</dd> <dd>Eswatini (formerly Swaziland)</dd> <dd>Ethiopia</dd> </dl> </div>
Without any CSS, the browser's default rendering is straightforward. However, the inherent structure of <dt></dt>
and <dd></dd>
allows for clever styling. Notice how the <dt></dt>
elements naturally align to the left due to the default margin. This makes creating "sticky sections" remarkably easy:
dt { position: sticky; top: 0; background: white; display: inline-block; }
The elegance of this solution is striking. The core functionality is achieved with minimal CSS. Further styling is purely cosmetic enhancement.
The 30 Seconds of Code example employs CSS Grid for a more robust layout, but this concise CSS approach highlights how much can be accomplished with less. They also offer a variation where <dd></dd>
elements span the full width, providing another interesting design option.
The above is the detailed content of Sticky Definition Lists. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The Svelte transition API provides a way to animate components when they enter or leave the document, including custom Svelte transitions.

If you’ve recently started working with GraphQL, or reviewed its pros and cons, you’ve no doubt heard things like “GraphQL doesn’t support caching” or

How much time do you spend designing the content presentation for your websites? When you write a new blog post or create a new page, are you thinking about

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

No matter what stage you’re at as a developer, the tasks we complete—whether big or small—make a huge impact in our personal and professional growth.

I'd say "website" fits better than "mobile app" but I like this framing from Max Lynch:

npm commands run various tasks for you, either as a one-off or a continuously running process for things like starting a server or compiling code.

It's out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.
