Skip to content

Instantly share code, notes, and snippets.

@JamesChevalier
Created December 21, 2011 15:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesChevalier/1506483 to your computer and use it in GitHub Desktop.
Save JamesChevalier/1506483 to your computer and use it in GitHub Desktop.
Transparent layers in HTML via three-div structure
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
html
{
/* Set background image so that transparency is easy to see */
background: #fff url(http://uhaweb.hartford.edu/CASS/unicorn.jpg) fixed no-repeat;
}
#container
{
/* Set specific size for container */
position: fixed;
width:300px;
height:500px;
}
#transparency
{
/* Match size of container, and make the layer transparent */
position: fixed;
width:300px;
height:500px;
background-color: grey; /* Any base color will do */
filter:alpha(opacity=70);
opacity: 0.7;
-moz-opacity: 0.7;
-khtml-opacity:0.7;
}
#content
{
/* Make content sit within the confines of the container */
position:relative;
}
</style>
</head>
<body>
<div id="container"> <!-- Container holds both transparency layer & content -->
<div id="transparency"></div> <!-- Transparency layer sits within container, below content -->
<div id="content"> <!-- Content sits on top of transparency layer, keeping it from being transparent as well -->
<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