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
Related
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>
On the image above the triangle is outer block, and the main block have 'overflow: hidden'. During the animation part of the animated image is cropped. In the main block necessary boundaries of complex shape. Any ideas how is this possible? Requirement of browsers - top versions chrome or firefox.
example: http://jsfiddle.net/F7Cz9/
This one is a little complex and I don't have all the styling down yet but by using pseudo-elements on a wrapper to create the triangle above...you can do it.
The hover is there just to show the "overflow" working.
Codepen.io Demo
HTML
<div class="super-wrap">
<div class="imgwrapper">
<img src="http://lorempixel.com/output/city-q-c-350-100-8.jpg" alt="" />
</div>
</div>
CSS
.super-wrap {
width:700px;
margin: 50px auto 0;
padding-top: 50px;
border:1px solid grey;
}
.imgwrapper {
width:700px;
position: relative;
}
.imgwrapper img {
display: block;
margin-left: 0;
transition:margin-left 1s ease;
}
.super-wrap:hover img {
display: block;
margin-left: 50%;
}
I'm trying to make opacity on only navigation background, but its applying on all inner divs like logo and nav, but I don't want apply opacity to logo background.
How can i make this possible?
I'm using code like this:
HTML
<div class="navigation">
<div class="logo"> logo image here </div>
<nav> navigation code here </nav>
</div>
Hi please use rgba background which only make background opacity
.outer {
background:rgba(0,0,0,0.5);
}
If your background is color (not image) then you can give color using rgba instead of hash like this: background-color: rgba(200,100,200,0.5) (last number is opacity from 0 to 1)
If you set the opacity of an element, it applies to all the elements it contains. You can give them an opacity as well, but it will be relative between 0 and the parent's opacity, as you can see here:
http://jsfiddle.net/hLw2c/
In other words, it's not possible to do it like this:
<div class="outer">YO<div class="inner">Zippazip</div></div>
.outer {
opacity: 0.5;
background-color: red;
}
.inner {
opacity: 1;
background-color: blue;
}
One possible workaround is to use a pseudo element to fake the background, like this:
http://jsfiddle.net/hLw2c/1/
<div class="outer">YO<div class="inner">Zippazip</div></div>
.outer {
position: relative;
}
.outer:before {
position: absolute;
display: block;
content: "";
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0.3;
background-color: red;
z-index: -1;
}
.inner {
opacity: 1;
background-color: blue;
}
Now, the header itself is fully opaque and doesn't have a background. The background is made by the :before pseudo element. This can be half transparent without affecting the other content of the header, because that content is not inside the pseudo element.
You should save png with opacity background (for example 80%), and change only the background of the needed div. That's all I think!
Example:
div#navigation {background: url('/src/image.png') center center repeat;}
In that case png with opacity works for element background, and all otrher things (texts, etc) are perfectly visible.
Example of image: http://jacekkowalewski.com/images/black85.png
Or add CSS rgba background style:
background:rgba(0,0,0,0.5);
<div class="navigation">
<div class="logo"> logo image here </div>
<nav> navigation code here </nav>
</div>
.navigation{
opacity:0.6;
}
.navigation #logo{
opacity:1.0;
}
I found a nice tutorial for making my images enlarge (like a zoom effect) on hover. The main difference between my needs and a tutorial is that I want my all images contained in a single box like container. So when I implemented the tutorial I realize that part of the enlarged image gets cut off when you hover. The effect is constrained to the container. I would like a way for the zoom to go wherever it needs to go on the page. (So you can see the whole zoomed image)
Here is my implementation of the tutorial: http://mulnix.contestari.com/wp/example225/1.php
JSFiddle: http://jsfiddle.net/dsRAH/
Original Code
Remove the overflow: hidden and all other overflows,
than for your images containers DIV remove float:left; and add display:inline-block;
* {
margin: 0;
box-sizing: border-box;
}
.wrapper {
position: relative;
background: #000;
color: #fff;
z-index: 0;
}
.photos {
position: relative;
display: flex;
flex-flow: row wrap;
}
.photo {
box-shadow: 0 0 0 2px #444;
margin: 5px;
position: relative;
max-height: 200px;
transform: translateZ(0);
transition: transform 0.5s;
}
.photo:hover {
z-index: 1;
transform: translateZ(0) scale(1.6);
}
.photo img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
.photo-legend {
position: absolute;
bottom: 0;
width: 100%;
padding: 1em;
background: rgba(0,0,0,0.3);
}
<div class="wrapper">
<div class="photos">
<div class="photo">
<img src="https://placehold.it/200x150/0bf" />
<div class="photo-legend">TEST DESCRIPTION</div>
</div>
<div class="photo">
<img src="https://placehold.it/200x200/f0b" />
</div>
<div class="photo">
<img src="https://placehold.it/200x150/bf0" />
</div>
</div>
</div>
It's not perfect but it's a start. I changed the overflow:hidden; in the wrapper to visible. I also put your code into jsfiddle so people can tinker with it.
http://jsfiddle.net/m8FXH/
You can try to use z-index. An element with greater z-index is always in front of an element with a lower z-index. If you main container is not overflow:hidden than you can try this out.
here is an example where you can see how it works. Hope that is helpful.
https://developer.mozilla.org/en-US/docs/Web/CSS/z-index
I would suggest giving your divs one of the following classes:
colleft for the ones that are at left column
colright for the ones that are at right column
rowtop for the ones at the top row
rowbottom for the ones at the bottom row
And then assign them the following properties
.colleft {
transform-origin-x: 0%;
}
....
transform-origin-x: 100%;
transform-origin-y: 0%;
transform-origin-y: 100%;
(respectively)
That will make the zoom go in the desired direction.
evan stoddard modified fiddle
I'm sorry if this is a duplicate. I looked through the related posts and couldn't find anything similar to what I'm dealing with.
I have an image that when hovered on, the opacity reduces. I have text in a DIV above the DIV containing the image, which is affected by the opacity setting of the image. The text is suppose to stay solid, while the image becomes transparent. Unfortunately, both elements are becoming transparent on hover. I thought that since the text is considered a parent element, it should not be affected by the opacity setting of the image.
html:
<div class="album large">
<div class="writing">
<h1>blah</h1>
</div>
<div class="opac">
<img src="background/runaways.jpg">
</div>
</div>
CSS:
.album img
{
display:block;
margin: auto;
}
.album.large
{
background-image: url('background/bigblack.jpg');
background-repeat: no-repeat;
background-position: center;
margin-bottom: 50px;
}
.writing
{
position: absolute;
color:red;
left: 50%;
margin-left: -270px;
}
.opac img:hover
{
opacity: .4;
filter:alpha(opacity=40);
}
Solve opacity issue of parent div
Using Pseudo-elements we can get rid of this, Check the link given below for more details.