Non-Transparent Text with html image and psuedo css classes - html

I need to place NON-transparent text on an image. This image is defined in the html. (This is so it can be dynamic). I style the transparency with an :after pseudo element. I would like to have text on this image. apprecaited
However, the problem I'm running into is that the text inherits the transparency. All of the other solutions I have found either define the picture in CSS or don't use a picture at all. Any help would be appreciated, thanks!
EDIT: A colored transparency is desired.
<div class="col-md-6" id="red-square-parent">
<%= image_tag 'infos/home/teaching-3.jpg' %>
<div class="centered">Don't Apply Transparency to me!</div>
</div>
#red-square-parent img{
height: 100%;
width: 100%;
object-fit: none;
}
// Overlay
#red-square-parent:after{
content: '';
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
background: rgba($comp-color-red, 0.7);
}

So, the issue is that you're applying transparency to the parent element. Just target the image specifically for transparency:
JSFiddle
#red-square-parent img{
position: relative;
opacity: 0.5;
}
#red-square-parent div{
position: absolute;
bottom: 40px;
color: black;
font-size: 50px;
}
<div class="col-md-6" id="red-square-parent">
<img src="http://i.imgur.com/eTmzQ.jpg"/>
<div class="centered">Don't Apply Transparency to me!</div>
</div>
In order to apply a coloured filter over this image, you will not be applying background-color as this will not change the color of the image at all.
What you instead need to do it a bit complicated, but you must apply a filter to the image.
I would recommend using a tool such as this: CSS Generator - Filter to get the desired color effect you want.
When you have the desired filter, update your code to look something like this (using the code generated from the CSS Generator - Filter site. See my JSFiddle
#red-square-parent img{
position: relative;
opacity: 0.5;
/* Filter */
filter: grayscale(50%) opacity(1) brightness(100%) contrast(100%) hue-rotate(500deg);
-webkit-filter: grayscale(50%) opacity(1) brightness(100%) contrast(100%) hue-rotate(500deg);
}
#red-square-parent div{
position: absolute;
bottom: 40px;
color: black;
font-size: 50px;
}
<div class="col-md-6" id="red-square-parent">
<img src="http://i.imgur.com/eTmzQ.jpg"/>
<div class="centered">Don't Apply Transparency to me!</div>
</div>

Related

Can a div using a clip path cut into another div?

What I'm trying to create is a div that cuts into two other divs (one above, and one below, see picture below)
First I had no idea how to create a shape like that in css until I discovered clip path: polygon. Now I can sort of get the shape going when using a shape generator, but the problem is I can't get the div to cut into the other places. I tried to use a z-index but that didn't work.
I know I can use a negative margin to move the div more into the hero image but the polygon doesn't come out right.
Here is JSFiddle I tried to add a snippet but was giving me too many issues, figured this would be easier and cleaner to see.
The HTML/CSS in particular is this:
<section class="ThreeSteps">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="col-lg-4">
<h2>Decide</h2>
<p>Pick</p>
</div>
<div class="col-lg-4">
<h2>Fundraise</h2>
<p>We</p>
</div>
<div class="col-lg-4">
<h2>Celebrate</h2>
<p>Give</p>
</div>
</div>
</div>
</div>
</section>
.ThreeSteps {
margin-top: -20px;
background-color: #0066CC;
-webkit-clip-path: polygon(0px 325px,1689px 491px,1688px -466px,1px 82px);
clip-path: polygon(0px 325px,1689px 491px,1688px -466px,1px 82px);
z-index: 1;
}
Anyone have any suggestions on what I should do? Thank you for your time.
I've seen that Clip Path just creates a mask on images. I think a better approach should be you create a pseudo-class :before and :after; positioning them absolute to the .ThreeSteps div.
something like this:
.ThreeSteps {
position: relative;
/*Other Stuffs*/
}
.ThreeSteps::before {
content: '';
width: 100%;
height: 100px;
display: block;
position: absolute;
top: -115px;
left: 0;
background: url('my-triangle-image-top.svg') no-repeat;
background-size: contain;
z-index: 2000;
}
.ThreeSteps::after {
content: '';
width: 100%;
height: 100px;
display: block;
position: absolute;
top: 0;
bottom: -115px;
background: url('my-triangle-image-bottom.svg') no-repeat;
background-size: contain;
z-index: 2000;
}
If you can use some Vector Image Editor (Like Adobe Illustrator), you can save a triangle image as 'my-triangle-image.svg', and use as a background image on pseudo-classes :before and :after . If you cant, just use a .png image, but svg is the best for this purpose.

:before overlay doesn't cover image when hovered on

So what I want is that when an image is hovered over the black overlay I have added with the :before covers the div and then I will add text and an image over the top of that later. With the current code it doesn't even seem to be recognising the hover. I'm also using foundation. Help would be much appreciated :)
<div class="small-12 large-4 columns">
<img class="tri" src="media/images/mountain.jpg">
</div>
.tri{
position: relative;
overflow: hidden;
display: block;
}
.tri:before{
opacity: 0.8%;
top: 100%;
width: 100%;
height: 100%;
transition: all 0.4s;
background-color: black;
position: absolute;
content: '';
}
.tri:hover::before{
top: 0%;
}
Unfortunately, ::before and ::after psuedoclasses aren't supported on self-closing elements like img and input.
You could simply wrap an additional div around the img and put the :hover and ::before properties on that.

Background image to fill only half of div

I have a div with a set size which I need to add a background image to. However I would like the image to fill the width of the div but be cropped to take up up say one third to a half of the height of the div. I've managed this using a pseudo element like so:
<div class="card-wrap bg-img-3"><div class="card">
<div class="top">
<h2 class="white">Heading</h2>
</div>
</div></div>
.bg-img-3:before {
content: '';
position: absolute;
width: 9.4cm;
height: 3cm;
z-index: -1;
background: url("./img/video.png");
}
But using this technique I don't seem to able to add a background colour to the bottom half of the div.
How can I use a cropped background image and background colour on the same div?
You can use after to set background color if you want
.bg-img-3:after {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: -2;
background-color: #f00;
}
If you call the background property alone, you will generalize your command. Instead, be more specific and use background-image. This will tell the browser you'll want to use various properties for your background. You may want to remove the pseudo element ":after" as I believe it is not required in this method. Try the following in your style:
.bg-img-3 {
content: '';
position: absolute;
width: 9.4cm;
height: 3cm;
background-image: url("./img/video.png");
background-repeat: no-repeat;
background-size: 9.4cm 1.5cm;
background-color: #999;
}
Please let me know if this helps. Cheers.

White overlay over an image

Hi i am aware that you can add a greyscale filter on an image, but would it be possible for a white overlay using the filter setting. I have to do it through css without the need for another div, to be absolute positioned over the image, with a white background and opacity setting changed. Just a simple image within a a tag:
<a href="#">
<img src="http://placehold.it/300x200" />
</a>
css is basic
a img{
display:block;
max-width:100%;
height:auto
}
Solution 1:
You may use the :after psuedo-element. For example, add a class of white-out to your <a> element, and then use the following CSS:
a.white-out {
position: relative;
display: inline-block;
}
a.white-out:after {
position: absolute;
content: '';
display: block;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(255,255,255,.5);
}
jsFiddle Demo
Solution 2:
Alternatively, you can try setting a white background on your <a> element, and reducing the opacity of the <img /> inside. For example:
a.white-out {
display: inline-block;
background: #fff;
}
a.white-out img {
opacity: 0.2;
}
jsFiddle Demo

CSS Opacity property does not apply as it should on :hover state

I have a strange problem with opacity property in CSS. So, I want a hover effect, image should get transparent green overlay. It seems that opacity is just applying to the overlay color(it turns lighter when you decrease opacity but image under the overlay does not appear). I have also tried to solve the problem with rgba, but no success.
It's a little hard to explain, so here is the fiddle: http://jsfiddle.net/4T3dc/3/
<style>
.col-sm-4 {
padding-top: 20px;
}
.col-sm-4 .img-responsive {
width: 350px;
height: 350px;
cursor: pointer;
}
.col-sm-4 .img-responsive#one-image {
background: url(http://shrani.si/f/e/jm/42FHXzWF/cover.png);
}
.col-sm-4 .img-responsive#one-image:hover {
background: #1abc9c;
opacity: 0.3;
}
</style>
<div class="row">
<div class="col-sm-4">
<div class="img-responsive img-rounded" id="one-image"alt="Responsive image">
</div>
</div>
</div>
Thank you!
You can add the green/opacity hover effect using :after.
Example on JSFiddle.
Make the following changes to your CSS:
.col-sm-4 .img-responsive#one-image {
position: relative;
}
.col-sm-4 .img-responsive#one-image:hover:after {
background: #1abc9c;
opacity: 0.3;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
content:"";
}
What your CSS presently does isn't overlay a colour on the background image - instead, it completely replaces the background image with the colour you specify, and gives it an opacity. One way to achieve what you're suggesting is to use an actual <img> element, and use the background of its container (.col-sm-4 .img-responsive#one-image) to simulate an overlaid colour by changing the image's opacity.
So your HTML would shift slightly to:
<div class="row">
<div class="col-sm-4">
<div class="img-responsive img-rounded" id="one-image" alt="Responsive image">
<img src="http://shrani.si/f/e/jm/42FHXzWF/cover.png">
</div>
</div>
</div>
And your new CSS style definitions would be:
.col-sm-4 .img-responsive#one-image img {
width:100%;
}
.col-sm-4 .img-responsive#one-image {
background:#1abc9c;
}
.col-sm-4 .img-responsive#one-image:hover img {
opacity: 0.7; /* 1 - 0.3, where 0.3 is the desired opacity of the colour overlay */
}
Here's a JSFiddle to demonstrate. Hope this helps! Let me know if you have any questions.
If you are using CSS3 you can use -webkit-filter.
-webkit-filter: hue-rotate(240deg) saturate(0.6);
Like in this Fiddle: http://jsfiddle.net/4T3dc/6/
I am not entirely sure if that's what you want from your description. However, you can use this website to tweak effects to get exactly what you want:
http://html5-demos.appspot.com/static/css/filters/index.html