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>
Related
I've made a responsive image grid and am trying to add a hover effect to it so that the image gets a dark overlay and some text fades in on it. However, I've been having a tough time implementing it.
Here's my HTML structure.
<div class="tile">
<img src="some_image" class="animate">
<div class="overlay">
<p>Mahatma Gandhi</p>
</div>
And here's my CSS
.gallery .row .tile:hover ~ .tile img {
transform: scale(1.2);
}
However upon hovering over the image, it does not have the expected behaviour.
What's wrong?
EDIT
I got the hover effect to work and I can now fade in text.
Here's my code for that:
<div class="tile">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d6/Tagore_Gandhi.jpg/220px-Tagore_Gandhi.jpg" class="animate">
<div class="overlay">
<div class="text">Mahatma Gandhi</div>
</div>
</div>
CSS
.tile {
position: relative;
width: 100%;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: rgba(0, 0, 0, 0.8);
}
.tile:hover .overlay {
opacity: 1;
}
This seems to work but I think it doesnt have a certain "feel" to it. So I need to add a scale effect to the image. How can I do that
Here is a jsFiddle that i think will help you to resolve your issue: https://jsfiddle.net/mcs3yn1x/
HTML
<div class="tile">
<img src="https://picsum.photos/200/300" class="animate">
<div class="overlay">
<p>Mahatma Gandhi</p>
</div>
CSS
.tile {
border: 2px solid black;
}
.tile:hover img {
transform: scale(1.2);
}
Edit
After hearing alittle more about your issue I have created the following jsFiddle: https://jsfiddle.net/f1gzonjr/4/
HTML
<div class="tile">
<div class="container">
<img src="https://picsum.photos/200/300" class="animate">
<div class="overlay">
<p>Mahatma Gandhi</p>
</div>
</div>
CSS
.tile {
position: relative;
top: 0px;
left: 0px;
height: 300px;
width: 200px;
overflow: hidden;
border: 2px solid black;
}
.container:hover img{
transform: scale(1.2);
}
.overlay{
position: absolute;
display: none;
top: 0px;
left: 0px;
height: 100%;
width: 100%;
background-color: rgba(0,0,0,0.5);
}
.overlay p {
position: relative;
text-align: center;
color: #fff;
}
.tile:hover .overlay{
display: block;
}
Here is an alternate solution. Not sure if its what you wanted.
.tile:hover img, .tile.hover img {transform: scale(1.2);}
Here is the original answer that I adapted: Change background color of child div on hover of parent div?
-----EDIT-----
To stop it scaling and breaking responsiveness you will need to add a container around the image and then set overflow to none.
HTML:
<div class="tile">
<div class="img-container"><img src="https://ichef.bbci.co.uk/news/660/cpsprodpb/16C0E/production/_109089139_928b0174-4b3f-48ff-8366-d118afa1ed56.jpg" class="animate"></div>
<div class="overlay">
<p>Mahatma Gandhi</p>
CSS:
.img-container{
width: 500px;
height: 500px;
overflow: hidden;
}
.tile:hover img, .tile.hover img {
transform: scale(1.2);
}
See the codepen below for an example
https://codepen.io/jamesCyrius/pen/pooqwwv
Here is a code
.zoom {
padding: 50px;
background-color: green;
transition: transform .2s; /* Animation */
width: 15px;
height: 15px;
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) */
}
<div class="zoom"></div>
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 want .thumb_text to grow when li.thumb_list <img> is hovered over. Currently, I can only get it to scale when I hover over the text, but not the <img>.
Also, for some reason the text is boldening no matter what weight or font family I give it.
li.thumb_list img {
-webkit-transform: scale(1.3);
transform: scale(1.3);
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
li.thumb_list:hover img {
-webkit-transform: scale(1);
transform: scale(1);
}
h1.thumb_text {
-webkit-transform: scale(1);
transform: scale(1);
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
h1.thumb_text:hover {
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
.photo_thumbnails {
display: inline-block;
width: 1300px;
height: 235px;
overflow: hidden;
position: relative;
}
.thumbnail_container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
transform: -webkit-translate(-50%, -50%);
transform: -moz-translate(-50%, -50%);
transform: -ms-translate(-50%, -50%);
}
li.thumb_list {
display: inline-block;
overflow: hidden;
height: auto;
margin: auto;
text-align: center;
position: relative;
}
h1.thumb_text {
position: absolute;
margin: auto;
top: 0;
left: 0px;
right: 0px;
bottom: 0;
color: #FFF;
height: 50px;
width: 200px;
z-index: 999;
vertical-align: middle;
text-align: center;
font-family: 'anonymous pro', monospace;
font-size: 20px;
font-weight: 100;
}
<div class="thumbnail_container">
<div class="photo_thumbnails">
<ul>
<li class="thumb_list">
<a href="http://scottnorris.co.uk/photos/uk.html"><img src="Photos/Thumbnails/UK.jpg" width="300" height="225">
<h1 class="thumb_text">uk landscapes</h1>
</a>
</li>
<li class="thumb_list">
<a href="http://scottnorris.co.uk/photos/asia.html"><img src="Photos/Thumbnails/Asia.jpg" width="300" height="225">
<h1 class="thumb_text">asian landscapes</h1>
</a>
</li>
<li class="thumb_list">
<a href="http://scottnorris.co.uk/photos/forgotten.html"><img src="Photos/Thumbnails/Lost.jpg" width="300" height="225">
<h1 class="thumb_text">lost & forgotten</h1>
</a>
</li>
<li class="thumb_list">
<a href="http://scottnorris.co.uk/photos/in-nature.html"><img src="Photos/Thumbnails/In_Nature.jpg" width="300" height="225">
<h1 class="thumb_text">in nature</h1>
</a>
<li>
</ul>
</div>
</div>
If you only want the text to increase while hovering img you can use the CSS sibling selector like this:
.thumb_list img:hover + .thump_text{
font-size:50px;
}
Note that if you Hover the text with only this CSS it will decrease again, given that you've only chosen the Hover effect for the img.
To get around this you have (at least) two choices: set the Hover effect to the container instead (no need for sibling selector then) or add pointer-events: none to the .thump_text
With regard to your font being only bold, I guess it could be because you only have one font-weight available with your custom font. Usually you have to provide the browser with different files for each weight of font. On the other hand though, the browser usually tries to create its own weight, when either of the extremes is applied (100 or bold/700). This is just a guess though, but could be a possible reason.
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;
}
I'm trying to do this 3D transformation effect using css transform :
In my attempt the hidden face appears from the right while it needs to appear from the bottom in mouse hover, I don't know what i'm doing wrong , any help on how to fix this would be greatly appreciated, thanks in advance for your feedback.
LIVE DEMO
HTML
<div class='box-scene'>
<div class='box'>
<div class='front face'>
<img src='http://placehold.it/180x180/' alt=''>
</div>
<div class="side face">
<p>This is back</p>
</div>
</div>
</div>
<div class='box-scene'>
<div class='box'>
<div class='front face'>
<img src='http://placehold.it/180x180/' alt=''>
</div>
<div class="side face">
<p>This is back</p>
</div>
</div>
</div>
CSS
.box-scene {
-webkit-perspective: 700;
width: 400px;
height: 200px;
margin: auto;
z-index: 999;
}
.box-scene:hover .box {
-webkit-transform: rotateX(-90deg);
}
.box {
width: 180px;
height: 180px;
position: relative;
-webkit-transform-style: preserve-3d;
-webkit-transition: all 0.4s ease-out;
-webkit-transform-origin: 90px -90px -90px;
/* float: left; */
margin: 30px auto;
}
.face {
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: visible;
-webkit-transform-origin: 0 0;
}
.front {
-webkit-transform: rotateY(0deg);
z-index: 2;
background: #d9d9d9;
}
.side {
background: #9dcc78;
-webkit-transform: rotateY(90deg);
z-index: 1;
left: 180px;
}
If the hidden face shall come from the bottom, you have to change its position and some of the initial rotation. Here's the new fiddle.If you want it to come from the side the only thing to change is replacing rotateX(-90deg) with rotateY(-90deg) for the .box-scene:hover .box part. See fiddle.