I found this code on https://thecodeplayer.com/index.php/walkthrough/3d-thumbnail-image-hover-effect and I want to make the image both responsive and whenever I change an image, the image has to scale to the div.
I tried to set: width: 100%; and height: auto; but it did not work. Is it because the HTML does not contain <img> tags? As I'm trying to learn I would appreciate any advice you have for me on how to solve this.
/*custom font - Montserrat*/
#import url(http://fonts.googleapis.com/css?family=Montserrat);
/*basic reset*/
* {margin: 0; padding: 0;}
/*forcing the body to take 100% height*/
html, body {min-height: 100%;}
/*a nice BG*/
body {
background: #544; /*fallback*/
background: linear-gradient(#544, #565);
}
/*Thumbnail Background*/
.thumb {
width: 400px; height: 300px; margin: 70px auto;
perspective: 1000px;
}
.thumb a {
display: block; width: 100%; height: 100%;
/*double layered BG for lighting effect*/
background:
linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.4)),
url("http://thecodeplayer.com/u/m/i1.png");
/*disabling the translucent black bg on the main image*/
background-size: 0, cover;
/*3d space for children*/
transform-style: preserve-3d;
transition: all 0.5s;
}
.thumb:hover a {transform: rotateX(80deg); transform-origin: bottom;}
/*bottom surface */
.thumb a:after {
/*36px high element positioned at the bottom of the image*/
content: ''; position: absolute; left: 0; bottom: 0;
width: 100%; height: 36px;
/*inherit the main BG*/
background: inherit; background-size: cover, cover;
/*draw the BG bottom up*/
background-position: bottom;
/*rotate the surface 90deg on the bottom axis*/
transform: rotateX(90deg); transform-origin: bottom;
}
/*label style*/
.thumb a span {
color: white; text-transform: uppercase;
position: absolute; top: 100%; left: 0; width: 100%;
font: bold 12px/36px Montserrat; text-align: center;
/*the rotation is a bit less than the bottom surface to avoid flickering*/
transform: rotateX(-89.99deg); transform-origin: top;
z-index: 1;
}
/*shadow*/
.thumb a:before {
content: ''; position: absolute; top: 0; left: 0;
width: 100%; height: 100%;
background: rgba(0, 0, 0, 0.5);
box-shadow: 0 0 100px 50px rgba(0, 0, 0, 0.5);
transition: all 0.5s;
/*by default the shadow will be almost flat, very transparent, scaled down with a large blur*/
opacity: 0.15;
transform: rotateX(95deg) translateZ(-80px) scale(0.75);
transform-origin: bottom;
}
.thumb:hover a:before {
opacity: 1;
/*blurred effect using box shadow as filter: blur is not supported in all browsers*/
box-shadow: 0 0 25px 25px rgba(0, 0, 0, 0.5);
/*pushing the shadow down and scaling it down to size*/
transform: rotateX(0) translateZ(-60px) scale(0.85);
}
<!-- Container -->
<div class="thumb">
<!-- Image -->
<a href="#">
<!-- Label -->
<span>Three-eyed Robot</span>
</a>
</div>
Related
I want to create a gradient border animation starting from the top left to the bottom right. The animation will be used for images within this div.
I tried every degree of angle, but didn't get this to work in the direction I want, it always starts at the right top or at the bottom right.
Also tried it with negative degree values.
.block {
position: relative;
margin: 30px auto 0;
width: 250px;
height: 250px;
background: #272727;
}
.block:before, .block:after {
content: '';
position: absolute;
left: -1px;
top: -1px;
background: linear-gradient(45deg, rgba(0,0,0,0)35%, rgba(0,204,255,1)50%, rgba(0,0,0,0)65%);
background-size: 400%;
width: calc(100% + 2px);
height: calc(100% + 2px);
z-index: -1;
animation: shine 8s linear infinite;
}
#keyframes shine {
to {
background-position: 400% center;
}
}
.block:after {
filter: blur(8px);
}
<div class="block"></div>
Update your code like below:
.block {
position: relative;
margin: 30px auto 0;
width: 250px;
height: 250px;
background: #272727;
}
.block:after {
content: '';
position: absolute;
inset: -1px;
background: linear-gradient(-45deg, rgba(0, 0, 0, 0)35%, rgba(0, 204, 255, 1)50%, rgba(0, 0, 0, 0)65%);
background-size: 400% 400%;
z-index: -1;
animation: shine 3s linear infinite;
filter: blur(8px);
}
#keyframes shine {
from {
background-position: 100% 100%
}
to {
background-position: 0 0
}
}
<div class="block"></div>
I am using the code below to rotate the image, but I can only achieve to rotate the image from front view to bottom view. I want to rotate the image from front view to left view. How can I achieve this?
body {
height: 100vh;
margin: 0;
}
.thumb {
width: 600px;
height: 400px;
perspective: 1000px;
}
.thumb a {
display: block;
width: 100%;
height: 100%;
background: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.4)), url("https://i.imgur.com/9NVqw8Q.jpg");
background-size: 0, cover;
transform-style: preserve-3d;
transition: all 0.5s;
}
.thumb:hover a {
transform: rotateX(80deg);
transform-origin: bottom;
}
.thumb a:after {
content: '';
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 36px;
background: inherit;
background-size: cover, cover;
background-position: bottom;
transform: rotateX(90deg);
transform-origin: bottom;
}
.thumb a:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
box-shadow: 0 0 100px 50px rgba(0, 0, 0, 0.5);
transition: all 0.5s;
opacity: 0.15;
transform: rotateX(95deg) translateZ(-80px) scale(0.75);
transform-origin: bottom;
}
.thumb:hover a:before {
opacity: 1;
box-shadow: 0 0 25px 25px rgba(0, 0, 0, 0.5);
transform: rotateX(0) translateZ(-60px) scale(0.85);
}
<div class="thumb">
</div>
Modify rotateX to rotateY since left view makes use of the vertical axis.
Modify the transform-origin to left as we are transforming with the left side as the rotating point.
Apply the similar changes to the pseudo elements for the 3D look as mentioned by #kaiido. I have commented the changes made.
body {
height: 100vh;
margin: 0;
}
.thumb {
width: 600px;
height: 400px;
perspective: 1000px;
margin: 100px; /* For snippet spacing */
}
.thumb a {
display: block;
width: 100%;
height: 100%;
background: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.4)), url("https://i.imgur.com/9NVqw8Q.jpg");
background-size: 0, cover;
transform-style: preserve-3d;
transition: all 0.5s;
}
.thumb:hover a {
transform: rotateY(45deg); /* 1 - From rotateX */
transform-origin: left; /* 2 - From bottom */
}
.thumb a:after {
content: '';
position: absolute;
left: 0px;
bottom: 0;
width: 36px; /* Interchanged width and height because horizontal transformation is now vertical transformation */
height: 100%;
background: inherit;
background-size: cover, cover;
background-position: bottom;
transform: rotateY(90deg); /* 1 - From rotateX */
transform-origin: left; /* 2 - From bottom */
}
.thumb a:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
box-shadow: 0 0 100px 50px rgba(0, 0, 0, 0.5);
transition: all 0.5s;
opacity: 0.15;
transform: rotateY(15deg) translateZ(-40px) scale(0.75); /* 3 - From rotateX */
transform-origin: bottom;
}
.thumb:hover a:before {
opacity: 1;
box-shadow: 0 0 25px 25px rgba(0, 0, 0, 0.5);
transform: rotateY(0) translateZ(-60px) scale(0.85); /* 3 - From rotateX */
}
<div class="thumb">
</div>
#manoj-kumar is right.
make use of rotateX to rotateY
also you have to set transform-origin and position for the :after to make it wrap on left
fiddle : https://jsfiddle.net/hellooutlook/6sagLtpk/2/
body {
height: 100vh;
margin: 0;
}
.thumb {
margin: 100px;
width: 600px;
height: 400px;
perspective: 1000px;
}
.thumb a {
display: block;
width: 100%;
height: 100%;
background: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.4)), url("https://i.imgur.com/9NVqw8Q.jpg");
background-size: 0, cover;
transform-style: preserve-3d;
transition: all 0.5s;
}
.thumb:hover a {
transform: rotateY(60deg);
/* From rotateX */
transform-origin: left;
/* From bottom */
}
.thumb a:after {
content: '';
position: absolute;
left: 0;
bottom: 0;
width: 30px;
height: 100%;
background: inherit;
background-size: cover, cover;
background-position: bottom;
transform: rotateY(110deg);
transform-origin: left;
/* extra */
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
}
.thumb a:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
box-shadow: 0 0 100px 50px rgba(0, 0, 0, 0.5);
transition: all 0.5s;
opacity: 0.15;
transform: rotateX(15deg) translateZ(-40px) scale(0.75);
transform-origin: bottom;
}
.thumb:hover a:before {
opacity: 1;
box-shadow: 0 0 25px 25px rgba(0, 0, 0, 0.5);
transform: rotateX(0) translateZ(-60px) scale(0.85);
}
<div class="thumb">
</div>
I'm trying to have an image inside a clip-path'd container display correctly. I wanted to add a slight zoom effect on hover as well.
A small part at the bottom is being cut off when not hovered.
However, once you hover the image and it zooms in, everything looks fine.
I cannot set a fixed height, which would solve the problem more easily since I want to add the image to a responsive flex container later.
I reduced the problem to its core in this jsfiddle: https://jsfiddle.net/pzf459cd/1/
.Image-Wrapper {
width: 50%;
}
.Image-Zoom-Wrapper {
clip-path: polygon(100% 0, 100% 91%, 62% 100%, 0 91%, 0 0, 62% 9%);
object-fit: contain;
}
.Image {
transition: all 0.5s linear;
}
.Image-Wrapper:hover .Image {
transform: scale(1.05, 1.05);
transition: all 0.5s linear;
}
body {
background-color: #000;
}
<div class="Image-Wrapper">
<div class="Image-Zoom-Wrapper">
<img class="Image" src="https://picsum.photos/id/304/500/300">
</div>
</div>
See my solution for a similiar task below. It works, but there might be an easier/better one.
jsfiddle: https://jsfiddle.net/fj5z7bue/
.wrap{
position: relative;
width: 50%;
filter: drop-shadow(3px 4px 8px rgba(38, 50, 56, 0.4));
}
.clip{
position: relative;
display: block;
overflow: hidden;
clip-path: polygon(60% 5%, 100% 0, 100% 95%, 60% 100%, 0 95%, 0 0);
height: 100%;
width: 100%;
background-color: rgb(240, 240, 240);
}
.pseudoimg{
width: 100%;
opacity: 0;
}
.img{
position: absolute;
top: 0;
left: 0;
z-index: 2;
background-image: url('https://picsum.photos/id/304/500/300');
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
min-height: 100%;
min-width: 100%;
transform: scale(1);
transition: all 0.4s ease-out;
}
.wrap:hover{
cursor: pointer;
}
.wrap:hover .img{
transform: scale(1.4);
transition: all 12s ease-out;
}
.button{
position: absolute;
height: 60px;
width: 60px;
border-radius: 30px;
background-color: rgb(255, 255, 255);
z-index: 3;
right: -15px;
bottom: -5px;
filter: drop-shadow(3px 4px 8px rgba(38, 50, 56, 0.4));
}
<div class="wrap">
<div class="button"></div>
<div class="clip">
<img class="pseudoimg" src="https://picsum.photos/id/304/500/300"/>
<div class="img"></div>
</div>
</div>
I'm using a psuedo element to fade a gradient over another div which has an image as a background for that div.
My html layout is like so:
<div class='portfolio_thumb'>
<div class='portfolio_thumb_caption'></div
</div
and my CSS for those items
.portfolio_thumb {
position: relative;
width: 100%;
height: 300px;
background-size: cover;
}
.portfolio_thumb .portfolio_thumb_caption:before {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(to bottom, rgba(72,76,97,0) 0%, rgba(72,76,97,0.8) 75%);
content: '';
opacity: 0;
transform: translate3d(0,50%,0);
}
.portfolio_thumb:hover .portfolio_thumb_caption:before {
transform: translate3d(0,0,0);
opacity: 1;
}
Right now the gradient fades in and starts to slide, but it is shown past the parent div. I only want the gradient shown within the bounds of the portfolio_thumb div. Also, both divs in that html snippet are the same heights. Does anyone have any ideas? I'm going for this kind of approach. http://tympanus.net/Development/HoverEffectIdeas/
Thanks!
Use overflow: hidden on the container to cut-off the gradient.
Use transform: translateY(x%) to move the gradient up and down. As we are not creating 3d animations, there is no point using translate3d, which requires more grunt to run.
The transition smoothly shows and hides the overlay
Complete Example
.portfolio_thumb {
position: relative;
background: url(http://lorempixel.com/output/animals-q-c-640-300-1.jpg);
background-size: cover;
overflow: hidden;
height: 300px;
width: 100%;
max-width: 840px;
margin: 0 auto;
}
.portfolio_thumb .portfolio_thumb_caption:before {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(to bottom, rgba(72, 76, 97, 0) 0%, rgba(72, 76, 97, 0.8) 75%);
content: '';
transition: all 0.5s;
transform: translateY(50%);
opacity: 0;
}
.portfolio_thumb:hover .portfolio_thumb_caption:before {
transform: translateY(0);
opacity: 1;
}
<div class='portfolio_thumb'>
<div class='portfolio_thumb_caption'></div>
</div>
I have a problem with the css3. I am currently following a tutorial then when I test it on my local copy, the css3 is not being read by the browser. here is the code:
<html>
<head>
<style type="text/css">
/*custom font - Montserrat*/
#import url(http://fonts.googleapis.com/css?family=Montserrat);
/* Background */
html, body{ min-height: 100%}
body {
background: #123;
background: linear-gradient(#123, #399);
}
/*basic reset*/
* {margin:0; padding: 0;}
/*Thumbnail BG*/
.thumb { width: 400px; height: 300px; margin: 70px auto;
perspective: 1000px;
}
.thumb a {
display: block; width: 100%; height: 100%;
background: url("http://thecodeplayer.com/u/m/i1.png");
transform-style: preserve-3d;
/* hover effect */
transform: rotateX(80deg); transform-origin:bottom;
}
</style>
</head>
<body>
<div class="thumb">
<a href="#">
<!-- LABEL -->
<span></span>
</a>
</div>
</body>
The part transform-style: preserve-3d and below is not being read by the browser when I test it. Am I doing something wrong? I am using sublime-text 2 to create it.
I am using Chrome ver32 btw.
You need to add the vendor prefix and I think you want your hover effect pulled out into another rule, see this working example http://plnkr.co/edit/e1WJ5ogErMW6R6TDwX20?p=preview
You are missing some part of CSS from the source,
Here is a Demo with full CSS
#import url(http://fonts.googleapis.com/css?family=Montserrat);
/*basic reset*/
* {margin: 0; padding: 0;}
/*forcing the body to take 100% height*/
html, body {min-height: 100%;}
/*a nice BG*/
body {
background: #544; /*fallback*/
background: linear-gradient(#544, #565);
}
/*Thumbnail Background*/
.thumb {
width: 400px; height: 300px; margin: 70px auto;
-webkit-perspective: 1000px;
}
.thumb a {
display: block; width: 100%; height: 100%;
/*double layered BG for lighting effect*/
background:
linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.4)),
url("http://thecodeplayer.com/u/m/i1.png");
/*disabling the translucent black bg on the main image*/
background-size: 0, cover;
/*3d space for children*/
-webkit-transform-style: preserve-3d;
transition: all 0.5s;
}
.thumb:hover a {-webkit-transform: rotateX(80deg); -webkit-transform-origin: bottom;}
/*bottom surface */
.thumb a:after {
/*36px high element positioned at the bottom of the image*/
content: ''; position: absolute; left: 0; bottom: 0;
width: 100%; height: 36px;
/*inherit the main BG*/
background: inherit; background-size: cover, cover;
/*draw the BG bottom up*/
background-position: bottom;
/*rotate the surface 90deg on the bottom axis*/
-webkit-transform: rotateX(90deg); -webkit-transform-origin: bottom;
}
/*label style*/
.thumb a span {
color: white; text-transform: uppercase;
position: absolute; top: 100%; left: 0; width: 100%;
font: bold 12px/36px Montserrat; text-align: center;
/*the rotation is a bit less than the bottom surface to avoid flickering*/
-webkit-transform: rotateX(-89.99deg); -webkit-transform-origin: top;
z-index: 1;
}
/*shadow*/
.thumb a:before {
content: ''; position: absolute; top: 0; left: 0;
width: 100%; height: 100%;
background: rgba(0, 0, 0, 0.5);
box-shadow: 0 0 100px 50px rgba(0, 0, 0, 0.5);
transition: all 0.5s;
/*by default the shadow will be almost flat, very transparent, scaled down with a large blur*/
opacity: 0.15;
-webkit-transform: rotateX(95deg) translateZ(-80px) scale(0.75);
-webkit-transform-origin: bottom;
}
.thumb:hover a:before {
opacity: 1;
/*blurred effect using -webkit-box shadow as filter: blur is not supported in all browsers*/
box-shadow: 0 0 25px 25px rgba(0, 0, 0, 0.5);
/*pushing the shadow down and scaling it down to size*/
-webkit-transform: rotateX(0) translateZ(-60px) scale(0.85);
}
Try This Link i have Prepared Demo
instead of using just
background: linear-gradient(#123, #399);
Use as below
background: -webkit-linear-gradient(#123, #399);
background: -moz-linear-gradient(#123, #399);
background: -o-linear-gradient(#123, #399);
background: linear-gradient(#123, #399);
Same for all other css3 property.
Read More about vendor prefix here or just search it.
Try it.
-moz-transform:rotateX(80deg);
-webkit-transform:rotateX(80deg);