I'm writing an interactive tutorial for a web app that is meant to highlight the various parts of the user interface. The tutorial is meant to spotlight one part at a time and tell the user how to interact with it. You've probably seen something similar on smartphone apps.
For the specific CSS that could be used to spotlight an existing interface, the best solution I've found is using something like this, which is just a div
on top of the existing interface that allows portions to be highlighted:
https://web.archive.org/web/20120414095101/http://svay.com/experiences/css3-spotlight
However, the CSS radial-gradient
only allows for circles and ellipses, which is strange for user interface elements that are usually rectangular. Is there a way to achieve the same effect but with rounded rectangles (dimmed area is everything outside the rectangle)?
Vals gave an excellent answer, and gave me a great hint to figure out a simple way to get exactly what I wanted. This effect can be achieved with an inset box shadow plus a regular one, and has the added benefit that the spotlight box need only be repositioned to highlight a particular area instead of redrawing a CSS gradient.
Here's the code:
One can tweak the parameters to make the gradient border softer or more dramatic, and how much it pokes into the spotlight.
Check out the following:
I have write a tiny jQuery plugin that create four div and place it arround your zone / element.
Even if it's not the answer you want don't vote down it's a first idea for your futur script.
http://jsfiddle.net/DoubleYo/DQ6jj/
You can do that with gradients, but achieving the rounded rectangle will be hard.
One easier way is just using box shadow
This way the rounded corners are easy. I have set a pseudo element to make it more elegant; this way you get 2 levels of transparency. You could elaborate it further using the remaining pseudo element, and also with an inset shadow.
demo
an alternate approach using gradients (no rounded corners, but not a bad effect anyway):
demo2
This is the non CSS3 solution. The solution uses a 10% transparency black background png, the spotlight is added as image down below.
HTML
JavaScript
CSS
The spotlight image
I tested this and it works on all modern and IE7+ desktop browsers.