XML technologies / CSS / CSS Cookbook / Design with CSS / Creating unexpected inconsistencies

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

You want to attract attention by combining two elements that do not normally belong together.

Solution

Place one element visually inside another. The site in the following figure shows Earth about to collide with an asteroid, combining Earth’s image with a billiards scene.

Earth’s image is superimposed on a billiards scene

Figure: Earth’s image is superimposed on a billiards scene.

The HTML for this example is straightforward:

<h2><span class="no">Earth News</span></h2>
<p>Earth escapes potential impact with killer asteroid; will we escape the next one in 2014? <a href="more.html">Read more</a></p>

The CSS defines the billiards scene as the background image of the element body, anchored in the upper-left corner. We also use the image replacement technique from the recipe Replacing HTML text with an image to replace an element h2 with Earth’s photograph:

<style type="text/css">
 body {
  background-color: #009E69;
  margin: 0;
  background-image: url(billiard.jpg);
  background-repeat: no-repeat;
 }
 h2 {
  background-image: url(earth.gif);
  position: absolute;
  width: 126px;
  height: 126px;
  z-index: 1;
  left: 166px;
  top: 69px;
 }
 .no {
  display: none;
 }
 p {
  width: 120px;
  margin: 260px 100px 0 170px;
  font-family: Verdana, sans-serif;
  font-size: small;
  font-weight: bold;
 }
</style>

Discussion

Showing something unexpected is an excellent way to attract attention. Skillfully combining two elements in one image (see also the following figure) can guide readers’ attention or simply reinforce the content’s meaning.

Combined photographs of a child and a man

Figure: Combined photographs of a child and a man.

This example uses two images: a billiard ball photograph as the background of the element body, and Earth’s image as the background of the element h2. Its value of position is set to absolute. The properties left and top then move Earth’s image into position, superimposing it on the billiards scene.

See also

The recipe Combining seemingly incompatible things to create contrast for combining seemingly incompatible elements, and the recipe Combining different image formats.

  

 

 

 

back to top