Faux-Overlay
Posted on | October 10, 2012 | No Comments
In a previous post I demonstrated a CSS Only Image Zoom. In this post I will explain how to do a CSS only overlay using the CSS3 box-shadow effect to focus the users’ attention onto the element being hovered on.
Live Demo
Here is the HTML Markup;
[html]
[/html]
And here is the CSS:
[css]
div
{
position:absolute;
top:25%;
left:40%;
width:20%;
height:20%;
background-color:#ff0000;
border:1px solid #000000;
text-align:center;
line-height:8em;
}
div:hover
{
-webkit-box-shadow:0 0 0 1000em rgba(0,0,0,0.2);
-o-box-shadow:0 0 0 1000em rgba(0,0,0,0.2);
-moz-box-shadow:0 0 0 1000em rgba(0,0,0,0.2);
box-shadow:0 0 0 1000em rgba(0,0,0,0.2);
}
[/css]
This is a very, VERY simple demonstration. We have a red div, that when hovered, puts a grey overlay over the rest of the screen. So, how can we use this in a real website? If we go back to my post on the image zoom again, this same technique has been used on the large images:
[css]
/* When the user hovers of the link,
show the bigImage and put an overlay over everything else */
ul li a:hover img.bigImage
{
-webkit-box-shadow:0 0 0 1000em rgba(0,0,0,0.2);
-o-box-shadow:0 0 0 1000em rgba(0,0,0,0.2);
-moz-box-shadow:0 0 0 1000em rgba(0,0,0,0.2);
box-shadow:0 0 0 1000em rgba(0,0,0,0.2);
visibility:visible;
}
[/css]
And no, this does not work in less than IE9. Still a cool effect, though.
Posted By:Richard Parnaby-King