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;
}
Related
I am having difficult making an overlay/hover command in CSS work correctly. I have 4 separate div's side by side, and when I put an overlay on it to make the picture fade on hover, it puts the hover effect on the other div's with the effect as well regardless of whether or not you are hovering over that div. I tried to restrict the hover to an image in the div, but could not The page that is having the trouble is- http://www.peel-lawfirm.com/practice-areas/workplace-injury
Here is my CSS code-
.fade {
opacity: 0.5;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.fade:hover {
opacity: 0.5;
}
.overlay {
position: absolute;
top: 0;
bottom: 10;
left: 0;
right: 10;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: #ffffff;
}
.container:hover .overlay {
opacity: 0.7;
overflow: hidden;
}
.text {
color: white;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
And here is my html for that portion of the page-
<div class="container">
<p>
<h3 style="text-align:center;">Practice Areas</h3>
<hr>
</p>
<div class="row">
<div class="col-md-3 col-sm-6 col-xs-12">
<p><jdoc:include type="modules" name="box1" /></p>
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
<p><jdoc:include type="modules" name="box2" /></p>
</div>
<div class="clearfix visible-sm"></div>
<div class="col-md-3 col-sm-6 col-xs-12">
<p><jdoc:include type="modules" name="box3" /></p>
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
<p><jdoc:include type="modules" name="box4" /></p>
</div>
</div>
</div>
You have .container:hover .overlay {...} which means when the .container div is hovered it will apply for all .overlay divs inside it. You need to apply the :hover only for the desired .overlay divs inside the .custom divs.
Change .container:hover .overlay {...} to .custom:hover .overlay
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 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>
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>
This is what I want it to look like:
everything that is inside the red div, must go behind the green div.
The html:
<div style="height: 100px">some text blablablablablablabla
<br/>some text blablablablablablabla
<br/>some text
<br/>some text
<br/>some text
<br/>some text
<br/>some text
<br/>
</div>
<nav class="navigation">
<div class="navfake"></div>
<div class="singleelement">
<div class="container">
<div class="title">Some Title1</div>
<div class="titlepicture">some picture</div>
</div>
</div>
<div class="singleelement">
<div class="container">
<div class="title">Some Title2</div>
<div class="titlepicture">some picture</div>
</div>
</div>
</nav>
The CSS so far and sadly not working:
nav {
width: 100%;
height: 60px;
position: relative;
}
.navfake {
width: 100%;
height: 100%;
background: green;
z-index: 10;
}
.singleelement {
display: inline-block;
width: 100px;
height: 60px;
text-align: center;
z-index: 0;
}
.container {
position: absolute;
top: 0px;
-webkit-transition: all .8s ease;
-moz-transition: all .8s ease;
-ms-transition: all .8s ease;
-o-transition: all .8s ease;
transition: all .8s ease;
height: 200px;
}
.titlepicture {
width: 100%;
height: 200px;
background-color: red;
}
.singleelement:hover .container {
top: -80px;
}
enter link description here
Credits also for: #Toskan, thank you
DEMO WORKING
Here's the new css
nav {
width: 100%;
height: 60px;
position: relative;
}
.navfake {
width: 100%;
height: 100%;
background: green;
z-index: 10;
position:relative;
}
.singleelement {
display: inline-block;
width: 100px;
height: 60px;
text-align: center;
}
.container {
position: absolute;
top: 0px;
-webkit-transition: all .8s ease;
-moz-transition: all .8s ease;
-ms-transition: all .8s ease;
-o-transition: all .8s ease;
transition: all .8s ease;
height: 200px;
}
.titlepicture {
position:absolute; /*THIS ADDED*/
width: 100%;
height: 200px;
background-color: red;
z-index:1; /*THIS ADDED*/
}
.singleelement:hover .container {
top: -80px;
}
.title{ /*THIS ADDED*/
z-index:555;
position:relative;
}
HTML:
<br><br>
<div style="height: 100px">some text blablablablablablabla
<br/>some text blablablablablablabla
<br/>some text
<br/>some text
<br/>some text
<br/>some text
<br/>some text
<br/>
</div>
<nav class="navigation">
<div class="navfake"></div>
<div class="singleelement">
<div class="container">
<div class="title">Some Title1</div>
<div class="titlepicture">some picture</div>
</div>
</div>
<div class="singleelement">
<div class="container">
<div class="title">Some Title2</div>
<div class="titlepicture">some picture</div>
</div>
</div>
</nav>
http://jsfiddle.net/hL5gW/4/
Adding position absolute and doing some positioning this is incredibly simple.
I added these styles to the second element. You'll just have to add it to a seperate class for the second element, or just add it to singleelement if you want this to apply to both.
<div class="singleelement" style="z-index:-100;position:absolute;margin-top:-60px;">