Remote linking with a twist

View Demo

Recently, I came across a scenario where a client wanted a list of links which would link to certain areas of the site. Additionally, they wanted to add a roll-over effect, where an image would change depending what link the mouse was hovering over. Without giving it a thought, I initially began to write some jQuery to do the trick, which would have been fine; but then I came across Chris Coyier’s remote linking article, and thought that I could build upon this to provide me with a CSS only solution.

There isn’t too much to this: it makes use of positioning and z-index to achieve this. Firstly we have the mark-up, which basically embeds each image, with the link text inside the anchor itself:

<ol>
    <li>
        <a id="red">Red Square
            <img src="images/red_square.png" alt="Red Square" />
        </a></li>
    <li>
        <a id="yellow">Yellow Circle
            <img src="images/yellow_circle.png" alt="Yellow Square" />
        </a></li>
    <li>
        <a id="green">Green Triangle
            <img src="images/green_triangle.png" alt="Green Triangle" />
        </a></li>
    <li>
        <a id="blue">Blue Hexagon
            <img src="images/blue_hexagon.png" alt="Blue Hexagon" />
        </a></li>
</ol>

And the CSS, where the magic happens:

#linksWrapper ol {
	list-style-type: none;
	margin: 0;
	padding: 0;
	position: relative;
}
#linksWrapper ol li {
	width: 180px;
}
#linksWrapper ol li a {
	text-decoration: none;
	padding: 0.25em 10px;
	display: block;
	color: #000;
	width: 160px;
}
#linksWrapper ol li a img {
	position: absolute;
	top: 0;
	left: 180px;
	z-index: 100;
	border: none;
}
#linksWrapper ol li a#red img {
	z-index: 500;
}
#linksWrapper ol li a#yellow:hover {
	background-color: #FFFC00;
	color: #000;
}
#linksWrapper ol li a#red:hover {
	background-color: #FF0000;
	color: #FFF;
}
#linksWrapper ol li a#green:hover {
	background-color: #24EA44;
	color: #FFF;
}
#linksWrapper ol li a#blue:hover {
	background-color: #2B99F6;
	color: #FFF;
}
#linksWrapper ol li a:hover img {
	z-index: 1000;
}
Tagged as

Leave a Reply

css gallery