I am trying to do something that's fairly straightforward and I've been looking through many examples but can't seem to get this to work as I expect. What I am trying to do if have an image that on hover will scale(1.1) and then add a background-color also. As you can see I have no problem with selecting the image within the image-holder that I created and scaling this on hover but then when I try to add the overlay to this and get that to add on hover it doesn't work. I attached the code below
<div class="image-holder">
<img src="https://cdn2.artbees.net/jupiter5/orthosie/wp-content/uploads/sites/51/bfi_thumb/portfolio-feature-07-msnw0wxnyitxdmhlcfsb7elky0xl4drzq8bc37266o.jpg" width="300" height="200">
<div class="image-overlay"></div>
</div>
.image-holder {
position: relative;
max-width: 33.333%;
float: left;
overflow: hidden;
}
.image-holder img {
width: 100%;
vertical-align: top;
transition: all 0.5s;
z-index: 2;
}
.image-holder:hover img {
transform: scale(1.1);
}
.image-overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: rgba(0,0,0,0.9);
opacity: 0;
z-index: 5;
}
.image-overlay:hover > img {
opacity: 1;
}
Related
I'm trying to build a card scheme where when you hover the mouse over the movie cover, some informations are displayed. The problem is: my star emoji doesn't reapear on hover.
I used this same visibility: hidden/visible with the center class, but with center-img it's not working.
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
.container {
margin: 20px;
width: 300px;
height: 424px;
background-color: black;
position: relative;
}
.fundo {
width: 300px;
height: 424px;
opacity: 1;
}
.center {
position: absolute;
top: 65%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 30px;
font-weight: 900;
font-family: "montserrat", sans-serif;
background: linear-gradient(to right,#ff8a00,#da1b60);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
visibility: hidden;
}
.center-img {
position: absolute;
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
width: 80px;
height: auto;
visibility: hidden;
}
.fundo:hover {
transition: .4s ease;
opacity: 0.5
}
.fundo:hover + .center {
visibility: visible;
}
.fundo:hover + .center-img {
visibility: visible;
}
</style>
</head>
<body>
<div class="container">
<img class="fundo" src="https://www.downgraf.com/wp-content/uploads/2015/06/Classic-Movie-Posters-8.jpg" alt="Cinque Terre">
<div class="center">10/10</div>
<img class="center-img" src="https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/160/samsung/161/white-medium-star_2b50.png">
</div>
</body>
</html>
I would like to see this shitty star to reapear on hover, if you guys can help me. Thanks in advance.
.container {
margin: 20px;
width: 300px;
height: 424px;
background-color: black;
position: relative;
}
.hover {
visibility: hidden
}
.fundo {
width: 300px;
height: 424px;
opacity: 1;
}
.center {
position: absolute;
top: 65%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 30px;
font-weight: 900;
font-family: "montserrat", sans-serif;
background: linear-gradient(to right,#ff8a00,#da1b60);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.center-img {
position: absolute;
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
width: 80px;
height: auto;
}
.container:hover .fundo {
transition: .2s ease;
opacity: 0.5
}
.container:hover .hover {
visibility: visible;
}
You have to switch your selector from .fundo:hover + .center-img to .fundo:hover ~ .center-img because <img class="center-img"> is not a direct sibling of <img class="fundo">.
The ~ selector will enable you to select any sibling of <img class="fundo"> that has the class of .center-img.
Using opacity transition
CodePen using opacity transition
.center-img {
position: absolute;
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
width: 80px;
height: auto;
opacity: 0; /* Add this */
}
.fundo:hover ~ .center-img { /* Change selector to this */
transition: 1.2s ease; /* Add this */
opacity: 1; /* Add this */
}
Using visibility property
CodePen using visibility property
.center-img {
position: absolute;
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
width: 80px;
height: auto;
visibility: hidden;
}
.fundo:hover ~ .center-img { /* Change selector to this */
visibility: visible;
}
Solving the flicker effect when you hover over the star or score by using an overlay
CodePen implementation of overlay
The idea is to create an invisible overlay that will cover the entire movie image and apply the hover effects onto the overlay.
The flickering was occurring in your solution because the hover effects were placed on the movie image, which was behind the star and score on the z-axis.
Once your mouse hovered over either the star or score, the visibility effect was essentially being toggled because your mouse was hovering over the star/score instead of the movie image. This resulted in the hover effects on the star/score would be taken off. Once the effects were taken off and their visibility was hidden, you were back to hovering over the movie image. This cycle is what created the flickering effect.
.fundo__overlay { /* Created new selector */
position: absolute;
z-index: 999; /* Give the overlay a higher stacking content */
top: 0;
left: 0;
width: 100%; /* Get it to match the movie image's dimensions */
height: 100%;
background: black;
opacity: 0; /* Used for hover transition */
}
/* Transferred hover effects */
.fundo__overlay:hover { /* Changed selector */
transition: opacity .4s ease;
opacity: 0.5
}
.fundo__overlay:hover ~ .center { /* Changed selector */
visibility: visible;
}
.fundo__overlay:hover ~ .center-img { /* Changed selector */
visibility: visible;
}
<div class="container">
<div class="fundo__overlay"></div> <!-- Added new element -->
<img class="fundo" src="https://www.downgraf.com/wp-content/uploads/2015/06/Classic-Movie-Posters-8.jpg" alt="Cinque Terre">
<div class="center">10/10</div>
<img class="center-img" src="https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/160/samsung/161/white-medium-star_2b50.png">
</div>
I am trying to add a sweep to the right animation on my image so that when you hover the image it sweeps to the right and it shows the text on hover as well. I got this to work just find with buttons but I am lost on how to go about doing this. This is what I have so far with my code:
.portfolio-box {
position: relative;
overflow: hidden;
z-index: 1;
}
.portfolio-box img {
width: 300px; /*changed this from 100% for the q*/
height:auto;
/*object-fit: contain;*/
}
.portfolio-mask {
position: absolute;
display: flex;
justify-content: center;
align-items: center;
opacity: 0;
background: #060606;
top: 0;
left: 0;
bottom: 0;
right: 0;
height: 100%;
width: 100%;
transform: scaleX(0);
transform-origin: 0 50%;
transition: transform 0.5s ease-out;
}
.portfolio-mask:hover:after {
transform: scaleX(1);
}
.portfolio-mask:hover {
opacity: .85;
color: white;
}
<div class="portfolio-box">
<img src="https://upload.wikimedia.org/wikipedia/commons/4/45/A_small_cup_of_coffee.JPG" alt="Coffee">
<div class="portfolio-mask">
<p class="portfolio-text">Design Mock up</p>
</div>
</div>
I made some changes to your CSS to make it work smooth and without insane jumping when you hover left side of the image. Here is the CSS and below is the description what changes and why I have made.
.portfolio-box {
position: relative;
overflow: hidden;
display: inline-block;
z-index: 1;
}
.portfolio-box img {
width: 300px; /*changed this from 100% for the q*/
height:auto;
transition: all 0.5s ease-out;
display: block;
/*object-fit: contain;*/
}
.portfolio-mask {
position: absolute;
display: flex;
justify-content: center;
align-items: center;
opacity: 0;
background: #060606;
top: 0;
left: 0;
bottom: 0;
right: 0;
height: 100%;
width: 100%;
transform: scaleX(0);
transform-origin: 0 50%;
transition: all 0.5s ease-out;
}
.portfolio-box:hover .portfolio-mask {
transform: scaleX(1);
opacity: .85;
color: white;
}
Changes I made:
Added display: inline-block; for .portfolio-box - to make it be as big as image inside.
Added display: block; for image to prevent 2-3px empty space under image when it is displayed inline (default).
Added transition: all 0.5s ease-out; for image, to prevent jumping when change position.
I changed transition from transform to all to animate not only move but opacity of mask container.
Animation are now added for hover on .portfolio-box, because it is static container, which is very important for effect you want to achieve - if you add animation on image hover then you will get infinite animation, because when you hover your mouse above image then it will slide to the right and after then it will be no longer hovered so it will go back to initial state and then it will be hovered again so it will go to the right... repeat initity ;)
I think from your description that what you are trying to do is a transform. For this, just add a translateX transform (of your desired size) to the css.
Hope this helps.
.portfolio-box {
position: relative;
overflow: hidden;
z-index: 1;
}
.portfolio-box img {
width: 300px; /*changed this from 100% for the q*/
height:auto;
/*object-fit: contain;*/
}
.portfolio-box img.animate:hover{
transform: translateX(5em);
}
.portfolio-mask {
position: absolute;
display: flex;
justify-content: center;
align-items: center;
opacity: 0;
background: #060606;
top: 0;
left: 0;
bottom: 0;
right: 0;
height: 100%;
width: 100%;
transform: scaleX(0);
transform-origin: 0 50%;
transition: transform 0.5s ease-out;
}
.portfolio-mask:hover:after {
transform: scaleX(1);
}
.portfolio-mask:hover {
opacity: .85;
color: white;
}
<div class="portfolio-box">
<img class="animate" src="https://upload.wikimedia.org/wikipedia/commons/4/45/A_small_cup_of_coffee.JPG" alt="Coffee">
<div class="portfolio-mask">
<p class="portfolio-text">Design Mock up</p>
</div>
</div>
I'm trying to animate between a full string of text and its abbreviation using CSS transformation transitions (demonstrated in the snippet below).
What I would ideally like to have happen is that letters that are not needed between the full and abbreviated string are scaled horizontally from 0% to 100% (or in the opposite manner), which I have functioning.
However, I would also like the non-transforming letters to compress in position as the transforming letters compress in width, and, while I can implement the former function, I cannot seem to get this one to work.
In short, the code I have written thus far successfully transforms all the letters, but leaves some letters jumping next to each other the moment the transition begins.
#bhead.smaller h1 {
position: fixed;
top: 2vh;
right: 0;
left: 0;
font-size: 3.5vh;
margin: auto;
padding: 0;
text-transform: lowercase;
transition: all 0.5s ease-out;
}
#bhead h1 div {
display: inline-block;
width: auto;
margin: 0;
padding: 0;
transition: all 5s linear;
}
#bhead h1 .del {
display: inline-block;
width: auto;
opacity: 1;
}
#bhead.smaller h1 .del {
transform: scaleX(0);
width: 0;
opacity: 0;
}
#bhead h1 .undel {
display: inline-block;
transform: scaleX(0);
width: 0;
opacity: 0;
}
#bhead.smaller h1 .undel {
transform: scaleX(1);
width: auto;
opacity: 1;
}
button {
position: fixed;
top: 15vh;
}
<body id="bhead">
<h1 id="header" class="middle unselectEase"><div>J</div><div class="del">o</div><div>r</div><div class="del">dan </div><div>Ma</div><div class="del"></div><div>nn</div><div class="undel">.com</div>
</h1>
<button onclick="document.querySelector('#bhead').className = document.querySelector('#bhead').className == 'smaller' ? '' : 'smaller'">Transform</button>
</body>
(You may need to expand the snippet in order for the spacing to work.)
Got it! After rediscovering that width must transition between two fixed values (which is also difficult with text), I was able to find this article, which described how max-width can be transitioned instead of width to avoid this altogether. The author provides a handy JSFiddle demo as well, but I've fixed the snippet below.
Given, there is a risk in setting the max-width attribute, but it's one I'm fine with taking in this specific instance.
#bhead h1 {
height: 6vh;
font-size: 6vh;
white-space: nowrap;
position: fixed;
right: 0;
left: 0;
}
#bhead.smaller h1 {
position: fixed;
top: 2vh;
right: 0;
left: 0;
font-size: 3.5vh;
margin: auto;
padding: 0;
text-transform: lowercase;
transition: all 0.5s ease-out;
}
#bhead h1 div {
display: inline-block;
margin: 0;
padding: 0;
transition: all 5s linear;
max-width: 20vw;
}
#bhead h1 .del {
display: inline-block;
opacity: 1;
}
#bhead.smaller h1 .del {
transform: scaleX(0);
max-width: 0;
opacity: 0;
}
#bhead h1 .undel {
display: inline-block;
transform: scaleX(0);
max-width: 0;
opacity: 0;
}
#bhead.smaller h1 .undel {
transform: scaleX(1);
max-width: 0;
opacity: 1;
}
button {
position: fixed;
top: 15vh;
}
<body id="bhead">
<h1 id="header" class="middle unselectEase"><div>J</div><div class="del">o</div><div>r</div><div class="del">dan </div><div>Ma</div><div class="del"></div><div>nn</div><div class="undel">.com</div>
</h1>
<button onclick="document.querySelector('#bhead').className = document.querySelector('#bhead').className == 'smaller' ? '' : 'smaller'">Transform</button>
</body>
I am trying to create a different loading animation (revealing content). I managed to get it to work pretty well on the desktop, but it doesn't want to work well on mobiles. On a mobile it will jerk or when it does catch up the animation has completed.
The animation is just 2 divs like this:
<div id="loader-wrapper">
<div class="loader-background"></div>
</div>
And the CSS is like this:
#loader-wrapper {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1000;
}
#loader-wrapper .loader-background {
position: fixed;
top: 0;
width: 100%;
height: 100%;
z-index: 1000;
background-color: #000000;
}
#loader-wrapper .loader-background::after {
content: "";
position: absolute;
border-radius: 100%;
top: -750px;
right: 0;
width: 2000px;
height: 2000px;
box-shadow: 0 0 0 20000px #000000;
transition: all 3s;
transform: scale(0.1);
opacity: 1;
/* Start off-screen */
}
.loaded #loader-wrapper {
visibility: hidden;
}
.loaded #loader-wrapper .loader-background::after {
transform: scale(1);
opacity: 0;
}
I have created this on code pen so you can see it in action:
https://codepen.io/r3plica/pen/rwLagV
Does anyone know of a way I can get this working without having the jerking motion?
I made this rollover:
jsfiddle.net/DH6Lu/
But as you can see the background image glitches. This is not the case when I don't use the opacity on the main div:
http://jsfiddle.net/6KT9p/
Any idea what is wrong?
<div id="opacity">
<div class="box">
<a class="link" href="#">
<div class="inner">
<img src="http://lorempixel.com/340/192/" width="340" height="192">
<div class="description">
<h3>titel2</h3>
</div>
</div>
</a>
</div>
</div>
.box {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
.inner {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
overflow: hidden;
}
.inner img {
position: absolute;
opacity: 1;
-webkit-transition: opacity 0.5s ease;
}
.inner img:hover {
opacity: 0.15
}
.description {
background: url(http://www.merkendiewerken.be/wp-content/themes/merkendiewerken/img/close-recent.png) #aaa repeat 0 0 fixed;
width: 340px;
height: 192px;
position: absolute;
z-index: -1;
}
.description h3 {
color: #fff;
font-size: 18px;
text-transform: uppercase;
text-align: center;
position: absolute;
}
#opacity {
opacity: 0.5
}
The problem arises from the fixed property of the background.
Set the CSS to
.description {
background: url(http://www.merkendiewerken.be/wp-content/themes/merkendiewerken/img/close-recent.png) #aaa repeat 0 0;
width: 340px;
height: 192px;
position: absolute;
z-index: -1;
}
and it will work
fiddle
The problem is also linked to the GPU handling this different from the CPU. The GPU is handling the background during the transtion, the CPU in the static states. If you set transform: translateZ(1px) - one of the usual tricks to enable GPU - the background will be permanently in an offset. It solves the glitch, but the look isn't correct.
I guess it glitches because .inner inherits the opacity from #opacity... but I don't know why. Interesting.
Still, I have a workaround for your case, if you want to keep the initial alpha to 0.5: make the .inner half visible, hide the .description unless it's hovered.
The adjacent sibling selector + is useful to show the description when the image is hovered.
Here's what you have to add (existent properties omitted):
.inner img {
-webkit-transition: opacity 0.5s ease;
opacity:0.5;
}
.inner img:hover{
opacity:0.15;
}
.inner img:hover + .description{
opacity:1;
}
.description {
-webkit-transition: opacity 0.5s ease;
opacity:0;
}
Here's a working demo for this.