MOBILE

Programming the Mobile Web : WebKit CSS Extensions (part 2) - Reflection Effects & Masked Images

1/20/2011 3:33:20 PM

3. Reflection Effects

Reflection or mirror effects are among the most-used effects in Web 2.0 designs. They can be used on any content, including images. Remember, though, that we are designing for mobile screens and we don’t want to waste too much space.


Warning:

The reflection image doesn’t change the layout or the size of the element’s original content box. It is only part of the container’s overflow.


To create a reflection effect in Safari on iOS, use the -webkit-box-reflect attribute with the following syntax:

-webkit-box-reflect: direction offset <mask-box-image>;

The direction can be above, below, left, or right; the offset is the distance (in px or %) from the original element at which the reflection should appear; and the optional mask-box-image is generally a gradient function that will work as a mask for the reflection image. If no mask image is defined, a normal mirror will be used.

The type of reflection effect typically seen on Web 2.0 websites has the following attribute values:

-webkit-box-reflect: below 3px -webkit-gradient(linear, left top, left bottom,
from(transparent), color-stop(0.5, transparent), to(white));

4. Masked Images

As of iOS 3.0, we have access to a typical graphic design feature that has been missing for years in web development: masked images. We can use a masked image to apply any regular or irregular crop to the original image or, if using an alpha mask (or even a gradient function), to create a really nice visual effect over any image, like a fuzzy border. The mask properties are analogous to the background properties. For applying a mask, we have a shortcut property, -webkit-mask, and specific properties for the position.

The syntax of the shortcut version with all the optional parameters is:

-webkit-mask: attachment, clip, origin, image, repeat, composite, box-image;

Of course, we also have access to all the properties separately, like -webkit-mask-attachment, -webkit-mask-clip, and so on. There are a lot of possibilities, but typically an image (alpha or not, PNG or SVG) or a gradient function is used as the image value. For example:
<img src="london.png" style="-webkit-mask-image:
-webkit-gradient(linear, left top, left bottom, from(rgba(0,0,0,1)),
to(rgba(0,0,0,0))); " />

<img src="london.png" style="-webkit-mask-image: url(old_picture_mask.png)" />

Other  
  •  Windows Phone 7 Development : Debugging Application Exceptions (part 2) - Debugging a Web Service Exception
  •  Windows Phone 7 Development : Debugging Application Exceptions (part 1) - Debugging Page Load Exceptions
  •  Programming the Mobile Web : JavaScript Libraries
  •  Programming the Mobile Web : Ajax Support
  •  Windows Phone 7 Development : Building a Phone Client to Access a Cloud Service (part 5) - Deploying the Service to Windows Azure
  •  Windows Phone 7 Development : Building a Phone Client to Access a Cloud Service (part 4) - Coding NotepadViewModel
  •  Windows Phone 7 Development : Building a Phone Client to Access a Cloud Service (part 3) - Coding the BoolToVisibilityConvert
  •  Windows Phone 7 Development : Building a Phone Client to Access a Cloud Service (part 2) - Coding MainPage
  •  Windows Phone 7 Development : Building a Phone Client to Access a Cloud Service (part 1) - Building the User Interface
  •  Building Android Apps : Detecting Browsers with WURFL
  •  Building Android Apps : Submitting Your App to the Android Market - Preparing a Release Version of Your App
  •  Windows Phone 7 Development : Creating a Cloud Service to Access the Cloud Database (part 2) - Implementing a WCF Service to Access the SQL Azure Database
  •  Windows Phone 7 Development : Creating a Cloud Service to Access the Cloud Database (part 1) - Generating an Object Model to Access the Cloud Database
  •  Windows Phone 7 Development : Using Cloud Services As Data Stores - Creating a Cloud Database
  •  iPhone Application Development : Working with Text, Keyboards, and Buttons (part 5) - Implementing the View Controller Logic
  •  iPhone Application Development : Working with Text, Keyboards, and Buttons (part 4) - Hiding the Keyboard
  •  iPhone Application Development : Working with Text, Keyboards, and Buttons (part 3) - Creating Styled Buttons
  •  iPhone Application Development : Working with Text, Keyboards, and Buttons (part 2) - Adding Text Views
  •  iPhone Application Development : Working with Text, Keyboards, and Buttons (part 1) - Adding Text Fields
  •  Building Android Apps : Controlling the Phone with JavaScript (part 3) - Accelerometer
  •  
    Top 10
    Next – Gen Broadband – Optimizing Your Current Broadband Connection (Part 4)
    Next – Gen Broadband – Optimizing Your Current Broadband Connection (Part 3)
    Next–Gen Broadband – Optimizing Your Current Broadband Connection (Part 2)
    Next–Gen Broadband – Optimizing Your Current Broadband Connection (Part 1)
    Side Channel Attacks Explained
    Canon EOS M With Wonderful Touchscreen Interface (Part 3)
    Canon EOS M With Wonderful Touchscreen Interface (Part 2)
    Canon EOS M With Wonderful Touchscreen Interface (Part 1)
    Canon Powershot G15 With Immaculate Photos And Superb Controls
    Fujifilm XF1 - Compact Camera With Retro Design
    Most View
    Silverlight : Binding Using a DataTemplate
    Tracking Results and Measuring Success : Tying SEO to Conversion and ROI
    Is It Time To Tweet? (Part 1)
    Sony Tablet P: Unusual Android tablet
    Logisys Dracula VGA Cooler
    Windows Phone 7 Development : Push Notifications - Implementing Toast Notifications
    Introduction to Windows 8 Administration : Installing Windows 8
    Mobile computing works everywhere
    iPhone 5: A New Angle (Part 2)
    Safeguard Your PC With Malwarebytes
    Windows Server 2003 : Extending IPSec Operations, Designing IPSec Policies to Meet Secure Communications Needs
    Thunderbolt - Chain Reaction
    Programming with SQL Azure : Record Navigation in WCF Data Services
    The Best Entry Level Phones – November 2012 (Part 4) - Motorola Motosmart
    Programming Hashing Algorithms (part 4) - Hashing Streamed Data
    V For Venerable One
    How To Back Up All Your Devices (Part 1)
    Installing Exchange Server 2010 : Installing the Edge Transport Server
    20 Essential Window 8 Apps (Part 1)
    Lumia 800 And 710 Are Updated To 7.5