Matrix of Rollovers

Avatar of Chris Coyier
Chris Coyier on (Updated on )

Here is a bona fide little CSS-Trick for ya’ll.

I knew I could make a “matrix” of squares with rollovers. Then I got to wondering if I could duplicate that matrix of rollovers elsewhere on the screen. I figured I could using the same technique as Remote Linking. Then I got to thinking I could make the rollover in the duplicate matrix different by using a different style of rollover.

matrixrollover.png

The technique is pretty simple. The HTML for a single cell is just:

<a class="singlecell"><em>.</em></a>

The em element is what kicks over and constructs the second matrix.

The CSS is a little more complex, but it’s not bad. The em gets relative positioning and a right value of 200, so it just gets kicked to the right 200px. The regular anchor element goes red on hover, and the em moves background position. Each cell has display block, a width and height of 10px, and is floated left to create the matrix.

.singlecell {
  width: 10px;
  height: 10px;
  display: block;
  color: white;
  background-color: white;
  float: left;
}

.singlecell em {
  position: relative;
  width: 10px;
  height: 10px;
  right: 200px;
  display: block;
  background: yellow;
  text-indent: -9999px;
}

.singlecell:hover {
  background: red;
}

.singlecell:hover em {
  background: blue;
}

This isn’t exactly super-useful as it is, but its a kinda neat trick that I could see being adapted into something more interesting.

See the Pen Matrix of Rollovers by Chris Coyier (@chriscoyier) on CodePen.