demosthenes.info

A blog by Dudley Storey on , , , , , , and anything else that strikes his fancy.

featured articles

popular favourites

CSS Masks: Radial Vignettes

Traditional photographic vignettes – the effect seen when filming a projected image, or in photos taken with old box cameras – have more of a “pincushion” appearance, with shadows becoming more visible at the corners of the image and less at the sides. The previous example in this used an inner box-shadow on a background image, and therefore tended to a rectangular appearance: any circular shadowing effect we achieved was due solely to curving the border of the element with border-radius. But when we keep the corners of the element’s box at right angles, and combine that same technique with a radial gradient:

  1. p#brooklyn-bridge {
  2. width: 768px; height: 498px; background-image:
  3. -moz-radial-gradient(center, ellipse closest-side, rgba(0,0,0,0),
  4. rgba(0,0,0,0.6)), url(brooklyn-bridge.jpg);
  5. background-image: -webkit-radial-gradient(center, ellipse closest-side,
  6. rgba(0,0,0,0), rgba(0,0,0,0.6)), url(brooklyn-bridge.jpg);
  7. background-image: -ms-radial-gradient(center, ellipse closest-side,
  8. rgba(0,0,0,0), rgba(0,0,0,0.6)), url(brooklyn-bridge.jpg);
  9. background-image: -o-radial-gradient(center, ellipse closest-side,
  10. rgba(0,0,0,0), rgba(0,0,0,0.6)), url(brooklyn-bridge.jpg);
  11. background-image: radial-gradient(center, ellipse closest-side,
  12. rgba(0,0,0,0), rgba(0,0,0,0.6)), url(brooklyn-bridge.jpg);
  13. box-shadow: inset 0 0 40px rgba(0, 0, 0, 1); color: rgba(0, 0, 0, 0);
  14. overflow: hidden; text-align: center; margin: 0 auto; }

…with an photograph by Stephen Cho, we get the effect you see at the top of this article. (Note that I am using the most recent version of the CSS3 radial gradient specification, together with support for multiple backgrounds. You will have to write extra CSS for older browsers).

web developer guide

featured comment

by JoelB in Goodbye, JQuery Validation: HTML5 Form Errors With CSS3

what i'm reading

A Storm of Swords: A Song of Ice and Fire: Book Three
A Storm of Swords: A Song of Ice and Fire: Book Three

what i'm watching

Californication: The Third Season
Californication: The Third Season

what i'm playing

Mass Effect 3 Collector's Edition
Mass Effect 3 Collector's Edition

what i'm hearing

Dub FX
Dub FX

blogs

podcasts

no ads ever

This blog is free of advertising, and always will be.

creative commons licensed

The content of this blog is free to use in whatever way you wish under the Creative Commons license.