Pure CSS Popups

If you've already seen the complexspiral demo, then this page layout probably seems a bit familiar. However, this time we aren't playing around with background images, or indeed images of any kind. Instead we're creating static-text popups purely through the power of CSS. The title of the page is intentional: there is no Javascript used in this document. For that matter, there aren't any images either. And once again, there are no proprietary extensions being employed here. It's all validated HTML and CSS, period, end of story.

Hands-on: What to Do

Any browser that does a good job of supporting positioning will get some of the stuff I did here correct, so continuing onward is probably worth it. The basic drill is this: mouse over the links on the left side of the page. Watch the space below the links. Make sure to mouse over all the links, back and forth, up and down...

Again I say it: no Javascript was used in the making of this page.

What the...? You lie!

I do not. Here's how it's done.

In every case, the "caption" text is a span element inside the actual hyperlinks. Here's one example from the source of this document:

<a href="http://www.meyerweb.com/eric/css/">Links<span>A collection 
of things which interest me, and might interest you</span></a>

To prevent the text from showing up when the page loads, I have the following style:

div#links a span {display: none;}

So they're gone, removed entirely from the document flow. Bringing them back, then, is a simple matter of switching the display to block and positioning the element whenever the associated link is hovered over with the mouse pointer. Thus we get the first two lines of this rule:

div#links a:hover span {display: block;
   position: absolute; top: 200px; left: 0; width: 125px;
   padding: 5px; margin: 10px; z-index: 100;
   color: #AAA; background: black;
   font: 10px Verdana, sans-serif; text-align: center;}

The last three lines relate to how the element will be styled when it appears, but the first two cause it to be made visible (display: block;) and position it appropriately.

Want to have even more fun? How about icons that appear on rollover?

A Minor Side Note

Notice how the hyperlinks appear to overlay the main-content border, and how that overlap really lights up when you're hovering over a link but still has a gray stripe down the middle of the overlap. That's done with nothing more complicated than a border on the hyperlinks themselves, the color and style of which change during the hover:

div#links a:hover {color: #411; background: #AAA;
   border-right: 5px double white;}

This effect works because I set up everything so the borders on the hyperlinks actually overlaps the border of the main content area. Because I'm positioning these elements using pixel measures, I can get things to line up appropriately and then style them however I like. it's a bit of a trick, of course-- by sticking to shades of gray, it's easier for me to create translucency effects. Someone with a sufficiently keen color sense could probably come up with better stuff than I did. (Like not putting light text on a dark background, for starters.)

Jump to