Skip to content

Instantly share code, notes, and snippets.

@isaaguilar
Created July 8, 2017 04:31
Show Gist options
  • Save isaaguilar/672b7d841aff6ba9b42aa56debfa8585 to your computer and use it in GitHub Desktop.
Save isaaguilar/672b7d841aff6ba9b42aa56debfa8585 to your computer and use it in GitHub Desktop.
Overlay on parent element css, js, html
<html>
<head>
<style>
.overlay {
position: absolute;
top: 0;
left: 0px;
bottom: 0px;
right: 0px;
z-index: 2;
background-color: rgba(50, 50, 50, .5);
}
#parent {
position: relative;
display: block;
background: white;
height: 200px;
width: 200px;
}
</style>
</head>
<body>
<div>
<div id="parent">
<div id="overlay" />
An overlay will be layed out over me when the button is pressed.
</div>
</div>
<div>
<button id="toggle">Set Overlay</button>
</div>
<script>
var overlay = $("#overlay")
var toggle = $("#toggle")
toggle.click(function() {
if (overlay.hasClass("overlay")) {
overlay.removeClass('overlay')
} else {
overlay.addClass('overlay')
}
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment