Last active
September 27, 2018 19:50
-
-
Save stevehanson/fc20c3fd9dfadeb0ea57 to your computer and use it in GitHub Desktop.
Mixin to achieve background-image with overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see http://stackoverflow.com/questions/4183948/css-set-background-image-with-opacity | |
@mixin transparent_bg($bg_image, $overlay_opacity: "", $overlay_color: "") { | |
background: -webkit-linear-gradient(left, rgba($overlay_color, $overlay_opacity), rgba($overlay_color, $overlay_opacity)), url($bg_image) no-repeat; | |
background: -moz-linear-gradient(left, rgba($overlay_color, $overlay_opacity), rgba($overlay_color, $overlay_opacity)), url($bg_image) no-repeat; | |
background: -o-linear-gradient(left, rgba($overlay_color, $overlay_opacity), rgba($overlay_color, $overlay_opacity)), url($bg_image) no-repeat; | |
background: -ms-linear-gradient(left, rgba($overlay_color, $overlay_opacity), rgba($overlay_color, $overlay_opacity)), url($bg_image) no-repeat; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.my-div { | |
@include transparent_bg('/bg-image.jpg', 0.4, #000); // black overlay with 40% opacity | |
background-size: cover; // can use any regular css properties to style background | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment