CSS hover over image and text - css

I have squares with text on a website homepage and I want to add hover effect but dont know which class to choose from my website
www.justtobe.com.au homepage
the first big grid image ( beach photo), I want to add a hover effect similar to this homepage grid
<h2 id="demo12">12. Opacity #2</h2>
<div class="hover12 column">
<div>
<figure><img src="https://nxworld.net/example/css-image-hover-effects/pic01.jpg" /></figure>
<span>Hover</span>
</div>
<div>
/* Opacity #2 */
.hover
figure {
background: #1abc9c;
}
.hover12 figure img {
opacity: 1;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
.hover12 figure:hover img {
opacity: .5;
}
Can someone please help?

There are a couple of things that you have to change if your picture to look the same as the one in the website you mentioned, but if you only want that hover effect then you just need to target the span
.hover12 span {
opacity: 1;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
cursor:pointer;
}
.hover12 span:hover {
opacity: .5;
display:block;
}
Example: https://jsfiddle.net/fhntLpmz/
Though, if you want it to look like the one in the website you mentioned, you need to change the structure of your html and then your css code.
<h2 id="demo12">12. Opacity #2</h2>
<div class="hover12 column">
<div class="wrapper">
<span>Hover</span>
</div>
<div>
Instead of using img to show the image, I use css to put it as a background, so that the Hover button is inside it.
.wrapper {
background-image:url(https://nxworld.net/example/css-image-hover-effects/pic01.jpg);
background-size:100%;
background-repeat:no-repeat;
width:300px;
height:200px;
}
Other than this, it's just another couple of css. Take this example: https://jsfiddle.net/0shmd21e/1/
There are multiple ways to do this, though. This is just one of them

Related

CSS3 fade in without fade out - one way transition

I want to animate my html only with css. A list should fade in, if I add a class ti the element but should immediately disappear, if I remove the class.
I tried several things with transitions in css3. But i seems that all transitions are for both, mount and unmount of an element.
The magic trick is to remove the transition in the basic class an append it in the show class.
$("button").on("click", function(){
$("#container").toggleClass("show")
})
#container {
color: white;
background: #357700;
opacity: 0;
overflow: hidden;
transition: none;
}
#container.show {
opacity: 1;
transition: all 1s;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>Show/Hide</button>
<div id="container">
<p>Hello World</p>
</div>

CSS animation causes images to flicker

I'm learning how to use transition: in CSS. But for some reason, my images keep flickering instead of giving me smooth animation. I'm developing in Windows 10 with the latest version of Chrome. Here is my code, which is very simple:
function toggleClass() {
var box = document.getElementById('box');
box.className = box.className.match(/active/) ? '' : 'active';
}
#box {
width:200px;
height:200px;
background-color:#999;
opacity:0;
transform:translate(0,30px);
transition:background-color 0.6s ease, opacity 0.6s ease, transform 0.6s ease;
}
#box.active {
opacity:1;
transform:translate(0,0);
}
img {
width:100%;
display:block;
filter: grayscale(100%) brightness(120%);
mix-blend-mode:multiply;
}
#box:hover {
background-color:red;
}
<button type="button" onClick="toggleClass()">Toggle Image</button>
<div id="box" class="">
<img src="https://i.stack.imgur.com/GwYD1.jpg" alt="">
</div>
What I want to do is when I press the Toggle Image button, I want a grey scale to fade in. Then when I mouse over the image, I want it to turn red since it is using the mix-blend-mode and the #box should have a red background color.
The problem is that every time I add the active to #box.active, the image doesn't "gradually fade in". Instead, a solid grey box scrolls up and fades in. Once the grey box completes animation, the image then "snaps" into view as if animation duration is 0 seconds. I don't want the image to "snap" into view...I want the image to fade in smoothly just like the grey box.
I want both the grey box and the grey picture to animate in smoothly together.
How do I make this happen?
EDIT
I noticed that if I add the line #box.active {background-color:transparent;}, then the image fades in. But the image is too bright. Applying a #box-active {background-color:#999;} had the same problem as the original question.
EDIT 2
I noticed that if I add these lines, it almost does what I need
#box { background-color:rgba(155,155,155,1); }
#box.active { background-color:rgba(155,155,155,0.9);}
For some unusual reason using rgba along with an alpha of 1 before the active class and an alpha of 0.9, seems to help a little. Now I see the browser "trying" to animate things in smoothly, it's just very choppy now.
Try adding transform: translateZ(0) on the child element img.
function toggleClass() {
var box = document.getElementById('box');
box.className = box.className.match(/active/) ? '' : 'active';
}
#box {
width:200px;
height:200px;
background-color:#999;
opacity:0;
transform:translate(0,30px);
transition:background-color 0.6s ease, opacity 0.6s ease, transform 0.6s ease;
}
#box.active {
opacity:1;
transform:translate(0,0);
}
img {
width:100%;
display:block;
filter: grayscale(100%) brightness(120%);
mix-blend-mode:multiply;
transform: translateZ(0); // this rules forces a new layer
}
#box:hover {
background-color:red;
}
<button type="button" onClick="toggleClass()">Toggle Image</button>
<div id="box" class="">
<img src="https://i.stack.imgur.com/GwYD1.jpg" alt="">
</div>
Theoretically your code is correct, this has been a bug in chrome for quite some time.
The translateZ(0) workaround forces chrome to draw seperate layers for the GPU to toy with. You can find more about layers here.
Also note that if you're going for visual consistency, you might have to go with some additional vendor prefixed styling.
As of now, Chrome, Firefox and Edge don't agree on what a blend should look like

Image hover CSS for revolution slider

I'm using revolution slider and I'm stuck with a problem. As an example I use the original demo from here: https://revolution.themepunch.com/wordpress-photography-slider.
On the tab 'portfolio' you see images that shrink in size with a transition and look a bit darker when you hover over them. This is what I want as well but I can't figure out how.
In revolution slider you can add classes, ID's and CSS to specific images so what I probably need is a CSS code that makes this possible. I've tried several codes I found online but none of them do the trick because they all come with an html part as well.
My guess was: the image is already there, I don't need the html part, only assign classes or id's to the images and then give each image the same kind of CSS code.
Am I on the right track with this? And can anyone help me with the code for it?
Many thanks in advance!
add a class, then do some css
for example:
<img class="slider-img">
.slider-img:hover {
{
let me know if you need help with the css.
EDIT:
try this.
wrap each of your images around 2 divs, slider-img and img-wrap:
<div class="slider-img">
<div class="img-wrap">
<img src="http://science-all.com/images/wallpapers/stock-image/stock-image-15.jpg">
</div>
</div>
then do some css:
.slider-img {
width: 200px;
cursor: pointer;
}
.slider-img img {
width: 100%;
}
.slider-img:hover .img-wrap {
background-color: black;
transform: scale(0.7);
-o-transform: scale(0.7);
-ms-transform: scale(0.7);
-moz-transform: scale(0.7);
-webkit-transform: scale(0.7);
transition: all .5s ease-in-out;
-o-transition: all .5s ease-in-out;
-ms-transition: all .5s ease-in-out;
-moz-transition: all .5s ease-in-out;
-webkit-transition: all .5s ease-in-out;
}
.slider-img:hover .img-wrap img{
opacity: 0.5;
}
basically what the css is doing is that when you hover over the main div (.slider-img), the div containing the image (.img-wrap) gets scaled down by 70% by the css -webkit-transform: scale(0.7);
it also gets a background color of black with an opacity of 80%. this gives the darkened image effect.
-webkit-transition: all .5s ease-in-out; gives a smooth transition effect.
if you are wondering why there are 5 different lines of css for the same thing, thats because each line targets specific browsers. -o- is opera, -moz- is firefox etc.
also, make sure to change the .slider-img width to match your needs.
check out the working example on js fiddle:
here

Need help on displaying text in a div when an Image Link is hovered over.

To paint the picture image I have two divs one on top to hold 5 thumbnail pics and the bottom div has 5 lines of text. The idea is when I hover over a picture div I want the project name of it to be displayed on the bottom div. I want this to happen for all 5 pictures. Been searching everywhere and found some things that were close but dead end. Any help is greatly appreciated as I am trying to help a student with their project. I am good with CSS I just can't wrap my head around this task.
Simple Demo
The HTML is pretty simple. The .photowrapper is optional, and the class could be just placed on the the a.
<div class="photowrapper">
<a href="#">
<img src="//placehold.it/200" alt="" />
<div class="label">Text</div>
</a>
</div>
We need everything to be an inline-block to act like an image.
.photowrapper {
border: 1px solid black;
display: inline-block;
}
.photowrapper a {
display: inline-block;
}
We default our label to being transparent. When our .photowrapper is hovered, its text color changes.
.photowrapper .label {
color: transparent;
}
.photowrapper:hover .label {
color: black;
}
If you want the underline, add another rule for .photowrapper:hover a where you set the decoration to underline. This disables it on hover and by default.
.photowrapper a {
text-decoration: none;
}
Absolute Positioning Demo
With the same HTML, we can position our labels so that they are in the same place.
.photowrapper .label {
opacity: 0;
color: black; background: yellow;
-moz-transition: opacity 1s ease;
-webkit-transition: opacity 1s ease;
transition: opacity 1s ease;
position: absolute;
top: 100%;
left: 0;
}
Fancyness
You can have supported browsers transition color changing for a less jerky result. Replace the label style with this:
.photowrapper .label {
min-height: 1em;
color: transparent;
-moz-transition: color 1s ease;
-webkit-transition: color 1s ease;
transition: color 1s ease;
}
demo
If your label is more than text, you can instead change/animate the opacity.
.photowrapper .label {
opacity: 0;
color: black; background: yellow;
-moz-transition: opacity 1s ease;
-webkit-transition: opacity 1s ease;
transition: opacity 1s ease;
}
.photowrapper:hover .label {
opacity: 1;
}
demo
What this does is uses the data attribute to attach a name, then when the image is hovered whatever is in the data attribute is set as the HTML for the p tag with the id "info"
In action: http://jsfiddle.net/calder12/HQQsb/
HTML
<div>
<img src="http://placehold.it/100x100" data-name="Image 1" class="project"/>
<img src="http://placehold.it/100x100" data-name="Image 2" class="project"/>
<img src="http://placehold.it/100x100" data-name="Image 3" class="project"/>
</div>
<div id="infodiv"><p id="info"></p></div>
jQuery
$(document).ready(function(){
$(".project").mouseover(function(){
$("#info").html($(this).data('name'));
}).mouseout(function(){
$("#info").html('');
});
});
You will need to use javascript or jquery to get it to appear on hover. Someone asked something pretty similar here:
http://stackoverflow.com/questions/1119956/hover-element-a-show-hide-element-b
Also there are many tutorials that can be accessed from a simple google search on creating a jquery script to do what you're asking. Let me know if you need anymore help or dont understand how to do it.

Why only chrome (and maybe safari) works good with transition (height,width)?

I have a textarea, which stretches (makes height bigger) smoothly:
<style type="text/css">
textarea {
height:20px;
width:170px;
transition-property: all 0.2s linear; /* PS: I don't want to write all prefixes in this question */
}
textarea:focus {
height:30px;
}
</style>
<div style="overflow:hidden;"><!--And some good styles-->
<textarea style="resize:none;padding:10px;"></textarea>
</div>
So, in chrome <div> stretches smoothly (and <textarea> too, what I want), but in opera and firefox <textarea> stretches smoothly, but <div> doesn't.
I tried to add transition to <div>, but without result..
Is there a solution of this? (PS: I have some ideas to solve it with javascript: just add class to <div> onfocus, but can I solve it without js?)
So, I did it: I just add class "active" to <div> on focus of textarea, and on blur: remove class "active" from <div>. All transformations doing by this class, like
div {
height: 20px;
transition: all 0.2s linear;
}
div textarea {
height: 10px;
transition: all 0.2s linear;
}
div.active textarea {
height:30px;
}
div.active {
height:40px
}
It works very well.

Resources