I have four equally sized images, all set to 20% width of the page
<div class="portrait">
<img src="#">
</div>
<div class="portrait">
<img src="#">
</div>
<div class="portrait">
<img src="#">
</div>
<div class="portrait">
<img src="#">
</div>
in my website that are horizontally aligned. On hover, I want the image to zoom inside the original border (like this https://codepen.io/math2001/pen/zZXBbj?editors=1100), which I did by a CSS3 transition and overflow: hidden.
.portrait {
float: left;
width: 20%;
overflow: hidden;
}
.portrait img {
width: 100%;
transition: transform 0.2s linear;
}
.portrait img:hover {
transform: scale(1.1);
}
The width of the image does not overflow past the original 20% constraint of the portrait, but the height does. I know the problem is that there is no fixed constraint for the height of the wrapper divs, but I don't know how to create one, since everything is percentage scaled. How can I fix this?
Put the transform on the container rather than the image:
.portrait {
float:left;
width:20%;
overflow:hidden;
transition:transform 0.2s linear;
}
.portrait img {
width:100%;
}
.portrait:hover {
transform: scale(1.1);
}
<div class="portrait">
<img src="http://placehold.it/250x250">
</div>
<div class="portrait">
<img src="http://placehold.it/250x250/000/ccc">
</div>
<div class="portrait">
<img src="http://placehold.it/250x250/aaa/eee">
</div>
<div class="portrait">
<img src="http://placehold.it/250x250/ccc/fff">
</div>
Did you try to use bigger definition for scale. For example:
.portrait:hover img {
transform: scale(1.4);
}
You need to set the img to display:block;
.portrait {
float: left;
width: 20%;
overflow: hidden;
}
.portrait img {
display: block; /* added property */
width: 100%;
transition: transform 0.2s linear;
}
.portrait:hover img {
transform: scale(1.4);
}
<div class="portrait">
<img src="http://placehold.it/250/f99">
</div>
Related
I am trying to make my images act like this: http://www.kas.tw/ (hover over images beneath the image carousel) but my images expand from the side and I can't figure out how to make the image still stay in its box, here is the code.
CSS
#image3{
top: 130%;
left: 20%;
display: none;
}
#cover1{
width: 5%;
height: 100%;
left: 47%;
background-color: green;
z-index: 2;
top: 94%;
position: absolute;
}
.zoom {
padding: 50px;
transition: transform .2s; /* Animation */
margin: 0 auto;
}
.zoom:hover {
transform: scale(1.5); /* (150% zoom - Note: if the zoom is too large,
it will go outside of the viewport) */
}
HTML
<DIV class='zoom' id='image1'><IMG width='50%' height='90%' src="slime3.JPG"></DIV>
<DIV id='image2'><IMG width='50%' height='90%' src="slime4.JPG"></DIV>
<DIV id='image3'><IMG width='50%' height='90%' src="slime5.JPG"></DIV>
<DIV id='image4'><IMG width='50%' height='90%' src="slime6.JPG"></DIV>
<DIV id='image5'><IMG width='50%' height='90%' src="slime7.JPG"></DIV>
<DIV id='image6'><IMG width='50%' height='90%' src="slime8.JPG"></DIV>
<DIV id='cover1'><DIV>
<DIV id='cover2'><DIV>
<DIV id='cover3'><DIV>
<DIV id='cover4'><DIV>
<DIV id='cover5'><DIV>
You can make images stay in the box without expanding its container size.
This can be done purely on CSS by using max-width,max-height to set a specific box size and to use overflow: hidden to hide the excess image when it expands past the width and height.
transform: scale(2,2) allows the image to zoom from the center.
Try this:
#holder {
max-width: 200px;
max-height: 200px;
overflow: hidden;
}
#holder img {
width: 100%;
-webkit-transition: all 0.8s ease;
-moz-transition: all 0.8s ease;
transition: all 0.8s ease;
}
#holder img:hover {
transform: scale(2,2);
}
<div id="holder">
<img src="https://picsum.photos/200/200">
</div>
You could try this
<div class="item">
<img>..</img>
</div>
and for css
.item:hover img {
-moz-transform: scale(1.1);
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
I have the following html code :
.logo {
display: inline-block;
width: 30px;
position: absolute;
top: 50%;
opacity: 0;
transition: 0.6s;
}
.container:hover .logo {
opacity: 1;
transition: 0.6s;
}
.container:hover .picture {
filter: brightness(0.7);
transition: 0.6s;
}
<div class="container">
<div class="element-header">
<div class="element">Foo</div>
<div class="element">Bar</div>
</div>
<div class="loader"> </div>
<img src="logo.png" alt="" class="logo">
<img src="picture.jpg" alt="" class="picture">
</div>
When .container is hovered, I want .logo to be at opacity:1 and .picture to be at filter: brightness(0.7).
When a try to apply those properties one-by-one at .container hover, each is working. But when both are set-up, only the filter one is working.
If you set the position to relative instead of absolute, both images will display. As the code stood, one image was getting lost. (I substituted my own images in and added a picture class to size the image)
The transition works fine though!
Try below:
.logo {
display: inline-block;
width: 100px;
//height:auto;
position: relative;
top: 50%;
opacity: 0;
transition: 0.6s;
}
.picture {
width: 500px;
height: auto;
float: left;
}
.container:hover .logo {
opacity: 1;
transition: 0.6s;
}
.container:hover .picture {
filter: brightness(0.7);
transition: 0.6s;
}
<div class="container">
<div class="element-header">
<div class="element">Foo</div>
<div class="element">Bar</div>
</div>
<div class="loader"> </div>
<img src="https://www.dcu.ie/sites/default/files/afu_logo2_1.jpg" alt="agefriendly" class="logo">
<img src="http://www.rachelgallen.com/images/mountains.jpg" alt="Mountains" class="picture">
</div>
Fiddle here
I am trying to make a hover zoom effect with multiple images:
images are centered on the page
keep dimensions while zooming in
image width is set inline at img tag
Here is what I tried so far:
.img-zoom {
display: inline-block;
width: 100%;
height: 100%;
position: relative;
overflow: hidden;
}
.img-zoom img {
-webkit-transform: scale(1.04);
-ms-transform: scale(1.04);
transform: scale(1.04);
-webkit-transition: 0.4s ease;
transition: 0.4s ease;
margin: 0px 20px;
}
.img-zoom img:hover {
-webkit-transform: scale(1.21);
-ms-transform: scale(1.21);
transform: scale(1.21);
}
<div style="text-align: center;padding: 5px;">
<div class="img-zoom">
<img src="http://lorempixel.com/600/210" width="300" />
<img src="http://lorempixel.com/600/210" width="300"/>
</div>
</div>
...but the images are extending on mouse hover.
It sounds like you want the images to zoom in without their width/height changing. I've modified your HTML a bit and placed the inline width parameter on the .img-zoom element. I think this accomplishes what you need.
.img-zoom {
display: inline-block;
position: relative;
overflow: hidden;
}
.img-zoom img {
display: block;
width: 100%;
transition: 0.4s ease;
transform-origin: 50% 50%; /* center zoom */
}
.img-zoom img:hover {
transform: scale(1.21);
}
<div style="padding: 5px; text-align: center;">
<div class="img-zoom" style="width: 300px;">
<img src="http://lorempixel.com/600/210" />
</div>
<div class="img-zoom" style="width: 300px;">
<img src="http://lorempixel.com/600/210"/>
</div>
</div>
I've been trying to make three images with a 'flipcard' effect for around a day and a half now and think I'm pretty close to a solution.
However, as you can see on the codepen, the only problem left is that when my images are in a static state (i.e. not being hovered over) you can still see the text lying on top of them.
I'd really appreciate it if anyone could come up with a way so that when the images are static, there is no text lying on top of them, but when they are hovered over they animate with the 'flipcard' effect - such as already occurs.
Basically, I'd just like the text hidden/removed when the images are in a static state but visible after the animation occurs - as if they were on the 'flipside' of the images! The rest is fine.
Appreciate any answers in advance, thanks guys! :-)
Codepen link - http://codepen.io/skoster7/pen/kkYEJk?editors=0100
HTML:
<div class="flexcontainer">
<div class="photo-container">
<div class="photo">
<img src="https://media2.giphy.com/media/kiXLfqncf42kg/200_s.gif" class="front" />
<div class="photo-desc back">Christmas tree</div>
</div>
</div>
<div class="photo-container">
<div class="photo">
<img src="http://hdwallpaperpoint.com/wp-content/uploads/2016/05/Happy-birthday-candles-on-cake-small-cake-hd-4k-wallpaper-300x200.jpg" class="front" />
<div class="photo-desc back">Happy Birthday</div>
</div>
</div>
<div class="photo-container">
<div class="photo">
<img src="https://www.walldevil.com/wallpapers/a76/thumb/halloween-jack-o039-lantern-pumpkin-ghost-cat-skull-spider.jpg" class="front" />
<div class="photo-desc back">Halloween</div>
</div>
</div>
</div>
CSS:
.flexcontainer {
display: flex;
perspective: 700px;
}
.photo {
position: relative;
z-index: 1000;
}
.photo-desc {
position: relative;
z-index: 100;
}
.photo-container {
position: relative;
margin-right: 10px;
transition-property: transform;
transition-duration: 2s;
transition-style: preserve-3d;
backface-visibility: hidden;
}
.photo-container:hover {
transform: rotateY(-180deg);
}
.back {
backface-visibility: visible;
position: absolute;
top: 10;
margin-top: -200px;
transform: rotateY(-180deg);
color: red;
}
The photo and back elements should be siblings (and not parent/child).
Here is a snippet (changed width/height of the elements to fit SO):
.flexcontainer {
display: flex;
perspective: 700px;
}
.photo {
width: 200px;
height: 150px;
transform: rotateY(0deg);
}
.photo img {
width: 200px;
height: 150px;
}
.photo-container {
transform-style: preserve-3d;
transition-property: transform;
transition-duration: 2s;
position:relative;
width: 200px;
height: 150px;
margin:10px;
}
.photo-container:hover {
transform: rotateY(-180deg);
}
.back {
transform: rotateY(180deg);
color: red;
}
.photo,
.back {
backface-visibility: hidden;
position:absolute;
left:0;
top:0;
}
.back {
transform: rotateY(180deg);
}
<div class="flexcontainer">
<div class="photo-container">
<div class="photo">
<img src="https://media2.giphy.com/media/kiXLfqncf42kg/200_s.gif" class="front">
</div>
<div class="back">Christmas tree</div>
</div>
<div class="photo-container">
<div class="photo">
<img src="http://hdwallpaperpoint.com/wp-content/uploads/2016/05/Happy-birthday-candles-on-cake-small-cake-hd-4k-wallpaper-300x200.jpg" class="front">
</div>
<div class="back">Happy Birthday</div>
</div>
<div class="photo-container">
<div class="photo">
<img src="https://www.walldevil.com/wallpapers/a76/thumb/halloween-jack-o039-lantern-pumpkin-ghost-cat-skull-spider.jpg" class="front">
</div>
<div class="back">Halloween</div>
</div>
</div>
And a working codepeng:
http://codepen.io/anon/pen/Egazvq?editors=1100
You can achieve this by adding display: none; to the .back class
and then adding a little something to your css:
.photo-container:hover .back {
display: block;
}
Here is an updated codepen as an example:
http://codepen.io/anon/pen/QKwRvA?editors=1100
Well, I enjoyed the challenge of this. I will go right ahead and add another solution for you.
.flexcontainer {
display: flex;
perspective: 700px;
}
.photo-desc {
position: absolute;
}
.photo-container {
position: relative;
z-index: 100;
margin-right: 10px;
transition-property: transform;
transition-duration: 2s;
transition-style: preserve-3d;
}
.photo-container:hover {
transform: rotateY(-180deg);
backface-visibility: visible;
}
.back {
position: absolute;
top: 10;
margin-top: -200px;
transform: rotateY(180deg);
color: red;
opacity: 0;
}
.photo-container:hover > .back {
opacity: 1;
transition: opacity 1s linear;
}
<div class="flexcontainer">
<div class="photo-container">
<img src="https://media2.giphy.com/media/kiXLfqncf42kg/200_s.gif" class="front">
<div class="back">
Christmas tree
</div>
</div>
<div class="photo-container">
<img src="http://hdwallpaperpoint.com/wp-content/uploads/2016/05/Happy-birthday-candles-on-cake-small-cake-hd-4k-wallpaper-300x200.jpg" class="front">
<div class="back">
Happy Birthday
</div>
</div>
<div class="photo-container">
<img src="https://www.walldevil.com/wallpapers/a76/thumb/halloween-jack-o039-lantern-pumpkin-ghost-cat-skull-spider.jpg" class="front">
<div class="photo-desc back">Halloween
</div>
</div>
</div>
Doing it this way, enables the text to "fade in" etc. Which i think looks kinda cool with your animation. I also got it so your images stay "appeared" when hovering over, rather than the flipside "disappearing" when animation is flipped.
As a side note: disappointed that others found another solution first :)
I have kind of a thumbnail with an image and some text inside. When I hover over the image, it zooms in.
Here is a fiddle:
https://jsfiddle.net/ShiroiOkami/r1awd3b4/
I want to achieve an effect that the image just zooms in, but it's size stays the same. I don't want it to grow. How to do it?
P.S. the code for instance:
<div class="wrapper">
<img src="https://pixabay.com/static/uploads/photo/2015/10/01/21/39/background-image-967820_960_720.jpg" style="width:150px;" class="grow">
<div class="description">
<h3>
Some title
</h3>
<p>
some text
</p>
</div>
CSS:
.wrapper{
background-color: #fff;
text-align: center;
width: 150px;
overflow: hidden;
}
.grow{
transition: all .2s ease-in-out;
-webkit-transition: all .2s ease-in-out;
-moz-transition: all .2s ease-in-out;
-ms-transition: all .2s ease-in-out;
-o-transition: all .2s ease-in-out;
}
.grow:hover{
transform: scale(1.1);
-webkit-transform: scale(1.1);
-moz-transform: scale(1.1);
-ms-transform: scale(1.1);
-o-transform: scale(1.1);
}
.description{
background-color: #fff;
overflow: hidden;
}
I've fixed your fiddle, so you'll get the required effect: https://jsfiddle.net/r1awd3b4/1/
What I've done is add an extra wrapper div around the image:
<div class="img-wrapper">
<img src="..." class="grow">
</div>
CSS:
.img-wrapper{
width: 100%;
height: 150px;
overflow: hidden;
}
.img-wrapper img{
display: block;
width: 100%;
}
Now the image can grow all it wants but since the wrapper will not, the image will not 'grow', but just 'zoom'.
may be you mean this effect?:
<div class="wrapper">
<div class="img-container">
<img src="https://pixabay.com/static/uploads/photo/2015/10/01/21/39/background-image-967820_960_720.jpg" style="width:150px;" class="grow">
</div>
<div class="description">
<h3>Some title</h3>
<p>some text</p>
</div>
</div>
and the css:
.img-container {
width: 150px;
height: 150px;
overflow: hidden;
}