- This topic has 12 replies, 7 voices, and was last updated 5 years, 7 months ago by
jkesling.
-
AuthorPosts
-
June 20, 2014 at 4:38 am #173272
PirateStef
ParticipantHI guys,
So I got a bit of a head scratcher.I have this:
#product { background: url("img/vanden1.jpg") no-repeat center; background-size: cover; }
I want to add something like this:
.yellowoverlay { /*overlay css here (#E6DD24)*/ }
html:
<div class="yellow overlay" id="product"></div>
But how to do this?
The important things are that the overlay is a separate class, and I don’t want to add extra html stuff. If the html is needed I wil use Jquery to make the div. (for easy overlays ;))what I found:
https://css-tricks.com/tinted-images-multiple-backgrounds/but this isn’t reusable on different div’s
June 20, 2014 at 4:55 am #173274Paulie_D
MemberSeems easy enough
June 20, 2014 at 4:59 am #173275PirateStef
ParticipantWhoa, quick answer!
Thanks Paulie, yes this works great. however now my <h1>
and everything else in my div is also under the overlay.
Do I need a different html structure?
June 20, 2014 at 5:09 am #173276Paulie_D
Membereverything else in my div is also under the overlay.
Isn’t that the point of an overlay or am I missing something?
June 20, 2014 at 5:39 am #173277Paulie_D
MemberOK…quick re-think.
I added a bg image to the
.box
and it seemed to work initially but it made the contents also be under the ‘overlay’So I switched the
:after
to a:before
thinking that would solve it but it didn’t.It’s should but I guess something else was going on.
Soooo…whilst dabbling I added
position:relative
to theh1
, switched out theopacity
setting for anrgba
background and BOOM!http://codepen.io/Paulie-D/pen/vGkHL
Not sure what the heck is wrong (it could be a bug) but using the universal selector for all elements inside the
.box
divs and addingposition:relative
gets it done.When others come on board I’m sure they will work out what I did wrong.
June 20, 2014 at 6:52 am #173286Paulie_D
MemberHmm…apparently, your Codepen isn’t working.
Someone else I emailed, suggested a jquery fix. The jquery would add a child div and this div woud have a class with background color and opacity ect.
A valid suggestion but I dislike ‘styling’ divs regardless of how they get on the page.
June 20, 2014 at 7:23 am #173287PirateStef
Participantdoes this work?
http://codepen.io/Piratestef/pen/gJqkrJune 20, 2014 at 7:43 am #173288Paulie_D
MemberYep…
June 24, 2016 at 7:34 am #243133dzffafido
ParticipantYou can just use z-index: 0; for the overlay and z-index: 1; for the div content and the problem is solved !
September 1, 2016 at 10:13 am #245114zen92
ParticipantI may be late to the party but anyways I hope to help someone :) I built on Paulie_D’s answer
December 24, 2016 at 6:03 pm #249330skittleswrapper
ParticipantGreat post.
August 30, 2017 at 10:41 pm #259630Nikhil Gowda
ParticipantHow to do it for image tag? instead of CSS background-image.
April 12, 2018 at 5:36 am #269730jkesling
ParticipantIf anyone shows up looking for this solution, there is a slightly easier way to do it. I adjusted PirateStef’s example so you can compare. It uses the
linear-gradient()
CSS background. You can’t stack a color background and an image, but, you can stack two images, andlinear-gradient()
returns a ‘rendered image’ as far as CSS is concerned. To get a solid color, semi-opaque overlay, just use the same starting and ending color for the arguments inlinear-gradient()
. I hope this helps anyone who comes here looking for a solution in the future. -
AuthorPosts
- The forum ‘CSS’ is closed to new topics and replies.