Silversleaves
E info@silversleaves.com
T +44 121 288 2824
  • Website Design
  •  ·
  • Commercial Photography

  • Database Development
  •  ·
  • Business Intelligence
  • Home
  • Silversleaves
    • Services
    • Portfolio
  • Web
    • CSS
      • Sticky Footer
      • CSS3 Opacity
    • Firefox Addons
      • DGSCheck
  • Database
    • Oracle Certification
      • SQL Fundamentals I - Part 1
        • Introduction
        • Relational Theory
        • DESCRIBE
      • SQL Fundamentals I - Part 2
        • SQL Operators & Expressions
        • WHERE
        • ORDER BY
        • Ampersand Substitution
      • SQL Fundamentals I - Part 3
        • Single Row Functions
        • Conversion Functions
        • Group Functions
      • SQL Fundamentals I - Part 4
        • Joining Tables
        • Subqueries
        • Set Operators
        • DML
        • Transactions
      • SQL Fundamentals I - Part 5
        • Manipulating Tables
        • Schema Objects
  • Business Intelligence
    • Coming Soon
  • Photography
    • Food
      • Sweet
      • Savory
    • Drink
      • Liquids
    • Interior
      • Hotel
  • Graphic Design
    • Branding
      • Logos
    • Print
      • Poster
      • Brochure
      • Advert
  • Partners
    • Élite Hotels, Turkey
    • Terzioğlu İnsaat, Turkey
  • Blog

CSS Techniques - CSS3 RGB Aplha

  • Description
  • The Code
  • Notes

RGBA Colours

Interested in the opacity used for the menu / header / footer on this site? The technique used is a new feature of CSS3, rgba (the 'a' stands for alpha). Essentially this technique allows you to specify the opacity for a single colour. The advantage of this is that the background color of a div can have an opacity value applied to it, whilst the text and images in that div are left untouched.

 rgba 10%
 opacity 10%

 rgba 30%
 opacity 30%

 rgba 60%
 opacity 60%

 rgba 90%
 opacity 90%

To the right is a red container div. Inside it on the left are divs that have had a RGBA opacity applied to the background colour, and on the right standard CSS opacity which is applied to the whole div. This clearly shows how standard opacity allows the background colour to show through the whole div.

Why is this important? Well if you have a photograph in the background, and you want to have a see-through background without affecting the text (as as per this website's header / footer / menu), then CSS3 RGBA is the way to do it.

A stripped down demo can be seen here.

CSS

HTML

Notes

To accomodate browsers that do not support RGBA just include the same values as rgb values. That way old browsers (i.e. the dreaded IE6) will not apply any opacity, whilst browsers that support rgba will have the opacity as intended, thus ensuring that the text remains readable.

© Silversleaves Limited 2012