Skip to content

Instantly share code, notes, and snippets.

@JamesChevalier
Created December 21, 2011 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesChevalier/1506869 to your computer and use it in GitHub Desktop.
Save JamesChevalier/1506869 to your computer and use it in GitHub Desktop.
Transparent layers in HTML via rgba background
<!DOCTYPE html>
<html>
<head>
<!-- Conditional statement because older versions of IE do not support rgba -->
<!--[if IE]>
<style type="text/css">
#container
{
background:transparent;
filter:progid:DXImageTransform.Microsoft.Alpha(opacity=70);
zoom: 1;
}
</style>
<![endif]-->
<style type="text/css">
html
{
/* Optional: Set background image so that transparency is easy to see */
background: #fff url(http://uhaweb.hartford.edu/CASS/unicorn.jpg) fixed no-repeat;
}
#container
{
/* Optional: Set specific size for container */
position: fixed;
width:300px;
height:500px;
background: rgb(50,50,50); /* Fallback background for browsers that don't support rgba */
background: rgba(50,50,50,.7); /* Transparent background for browsers that support rgba */
}
</style>
</head>
<body>
<div id="container"> <!-- Container is itself transparent -->
<div id="content"> <!-- Content is present because of IE limitations -->
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<img src="http://s3.amazonaws.com/kym-assets/entries/icons/original/000/004/006/y-u-no-guy.jpg?1308157550" alt="Why u no" />
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment