Issue with CSS Enlarge on Hover Effect - html

I found a nice tutorial for making my images enlarge (like a zoom effect) on hover. The main difference between my needs and a tutorial is that I want my all images contained in a single box like container. So when I implemented the tutorial I realize that part of the enlarged image gets cut off when you hover. The effect is constrained to the container. I would like a way for the zoom to go wherever it needs to go on the page. (So you can see the whole zoomed image)
Here is my implementation of the tutorial: http://mulnix.contestari.com/wp/example225/1.php
JSFiddle: http://jsfiddle.net/dsRAH/
Original Code

Remove the overflow: hidden and all other overflows,
than for your images containers DIV remove float:left; and add display:inline-block;
* {
margin: 0;
box-sizing: border-box;
}
.wrapper {
position: relative;
background: #000;
color: #fff;
z-index: 0;
}
.photos {
position: relative;
display: flex;
flex-flow: row wrap;
}
.photo {
box-shadow: 0 0 0 2px #444;
margin: 5px;
position: relative;
max-height: 200px;
transform: translateZ(0);
transition: transform 0.5s;
}
.photo:hover {
z-index: 1;
transform: translateZ(0) scale(1.6);
}
.photo img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
.photo-legend {
position: absolute;
bottom: 0;
width: 100%;
padding: 1em;
background: rgba(0,0,0,0.3);
}
<div class="wrapper">
<div class="photos">
<div class="photo">
<img src="https://placehold.it/200x150/0bf" />
<div class="photo-legend">TEST DESCRIPTION</div>
</div>
<div class="photo">
<img src="https://placehold.it/200x200/f0b" />
</div>
<div class="photo">
<img src="https://placehold.it/200x150/bf0" />
</div>
</div>
</div>

It's not perfect but it's a start. I changed the overflow:hidden; in the wrapper to visible. I also put your code into jsfiddle so people can tinker with it.
http://jsfiddle.net/m8FXH/

You can try to use z-index. An element with greater z-index is always in front of an element with a lower z-index. If you main container is not overflow:hidden than you can try this out.
here is an example where you can see how it works. Hope that is helpful.
https://developer.mozilla.org/en-US/docs/Web/CSS/z-index

I would suggest giving your divs one of the following classes:
colleft for the ones that are at left column
colright for the ones that are at right column
rowtop for the ones at the top row
rowbottom for the ones at the bottom row
And then assign them the following properties
.colleft {
transform-origin-x: 0%;
}
....
transform-origin-x: 100%;
transform-origin-y: 0%;
transform-origin-y: 100%;
(respectively)
That will make the zoom go in the desired direction.
evan stoddard modified fiddle

Related

How to make image blurred but make edges crisp

Please, don't say anything like OH THERE ARE A LOT OF ANSWERS OUT THERE. I founded a lot of them, but none of them worked. This is HTML:
<img src="images/ONamaImg.png" class="main-page-img"> (not all of the HMTL of course, only pic code)
And here is CSS:
.main-page-img
{
filter: grayscale(100%) blur(10px);
float: right;
width: 550px;
height: 700px;
z-index: -1;
border-radius: 1000px 0px 0px 1000px;
margin-top: -350px;
box-shadow: 0px 0px 30px #777777;
overflow:hidden;
}
Thanks!
First, wrap the image in a container :
<div class="container">
<img src="path/to/image.jpg">
</div>
Then, add these css rules to the container and image:
.container {
overflow: hidden;
height: /*add height*/;
width: /*add width*/;
}
img {
margin: -10px;
}
Note: I didn't add other styles. Make sure to add them.
The basic concept is to wrap the blurred image in the container and clip the blurred edges using negative margins.
I also found a lot of answers that don't seen to solve the problem.
Here is my attempt:
HTML
First I created a container and added an image to use as the crisp border.
<div class="container">
<img class="border-img" src="https://pbs.twimg.com/profile_images/2209676047/gatinho-5755_400x400.jpg" />
<div class="blur-img"></div>
</div>
CSS
Then I use the same image as a background to an epty div inside the container. Within the div backgroud I can scale and adjust the images to make then appear like one.
.container {
width: 450px;
height: 500px;
overflow:hidden;
}
.blur-img {
width: 70%;
height: 70%;
background-image: url("https://pbs.twimg.com/profile_images/2209676047/gatinho-5755_400x400.jpg");
background-position: center;
transform: scale(1.2); /* use scale to zoom image */
filter: blur(10px);
position:relative; /* adjust position */
left:15%;
top:15%;
}
.border-img {
width: 450px;
height: 500px;
position:fixed;
}
Output
And the output looks like this:

Why div is being affected from his child?

Empty div like this :
<div class="section" id="s"> </div>
will be at the size of the screen.
But if I put another empty div inside, this section div height will be 0, or it will be in the height of the child's content.
<div class="section" id="s">
<div class="Back"> </div>
</div>
will make this section height to be 0, unless I put something inside Back which will make the section height= openBack's content.
I need to set the section size to be the screen size no matter what happens inside it, and I couldn't.
CSS :
html {
height: 100%;
}
body {
min-height: 100vh;
}
.section {
height: 100%;
width: 100%;
}
.Back {
background-image:url("/images/bg.png");
width: 100%;
height: 100%;
background-size: cover;
justify-content: center;
align-items: center;
}
How can you set the section size to stay screen size constant ?
NOTE: I was answering the original question
You might want to try this:
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
border: 1px solid black;
display: block;
would be able to cover parent div.
Check the following fiddle or snippet:
.hidden{
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
border: 1px solid black;
display: block;
background-color: rgba(254,204,254,0.5);
align-items: center;
flex-direction: column;
}
div.openBack {
position:relative;
border:1px dashed red;
display:flex;
justify-content:center;
align-items:center;
overflow:hidden
}
div.openBack img {
flex-shrink:0;
min-width:100%;
min-height:100%
}
<div class=openBack style="width:100px; height:200px">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/5/55/Mona_Lisa_headcrop.jpg/36px-Mona_Lisa_headcrop.jpg">
<div class="hidden"></div>
</div>
Try below css -
.openBack{ position:relative;}
.hidden{
position:absolute;
top:50%;
left:50%;
transform: translate(-50%, -50%);
z-index:9999;
}
To use an image as a background to a section or div, you don't want to include that image as an element. It's pushing the other elements around it out of the way, this is why the next div is pushed below it. And it would be more complicated than necessary to try to get that to behave well by using absolute position.
I would suggest attaching the image as the background-image to either your section's class or id, and remove the <img> element from the html.
either:
.openBack {
background-image: url("/folder/file.png");
}
or
#one {
background-image: url("folder/file.png");
}
You'll want to look up the properties of CSS' background-image to get it to scale and fit the exact way you want.
And you can't use number values at the beginning of IDs.
Hope this helps!
Thanks for all the answers, I found out that the solution was pretty simple (stupid).
The inner div closing tag was wrong <div> instead of </div> which messed up the structure.
Wish I had a tool to find such a mistake.

overlaying rollover images on top of each other using CSS

It seems simple but for some reason won't work. I need Image 2 to work as a rollover and be centered in the middle of the first one but on top of it. I have this so far:
.image1 {
z-index: 1;
top: 10vh;
width: 100%;
position: static;
}
.image2 {
z-index: 3;
margin-left: auto;
margin-right: auto;
padding; 4vh;
position: fixed;
}
<div>
<img class="image1" draggable="false" src="https://icdn2.digitaltrends.com/image/google-campus-hq-headquarters-home-offices-720x720.jpg?ver=1.jpg" alt="Alt Tag">
<img class="image2" src="https://vignette.wikia.nocookie.net/logopedia/images/2/28/Google_2015.svg/revision/latest?cb=20170804092955" onmouseover="this.src='https://vignette.wikia.nocookie.net/logopedia/images/2/25/Google_2015_%28Black%29.svg/revision/latest?cb=20171130074159'" onmouseout="this.src='https://vignette.wikia.nocookie.net/logopedia/images/2/28/Google_2015.svg/revision/latest?cb=20170804092955'">
</div>
Image one displays fine but image 2 displays below it or on top of the content that's below instead of on top of the image. I'd rather use CSS to do this than JavaScript but can't really find a way for either when it's a rollover?
Thanks in advance.
Edit;
like this:
How It Should Look
The following will do:
.parent {
max-width: 100vw;
display: flex;
justify-content: center;
align-items: center;
}
.image1 {
max-width: 100%;
}
.image2 {
position: absolute;
margin: auto;
max-width: 65%;
}
#media (min-width: 600px) {
.image2 {
max-width: 600px;
}
}
body {
margin: 0; /* cancel default 8px margin on SO */
}
* {
box-sizing: border-box; /* make elements include paddings in width/height */
}
<div class="parent">
<img class="image1" draggable="false" src="https://icdn2.digitaltrends.com/image/google-campus-hq-headquarters-home-offices-720x720.jpg?ver=1.jpg" alt="Alt Tag">
<img class="image2" src="https://vignette.wikia.nocookie.net/logopedia/images/2/28/Google_2015.svg/revision/latest?cb=20170804092955" onmouseover="this.src='https://vignette.wikia.nocookie.net/logopedia/images/2/25/Google_2015_%28Black%29.svg/revision/latest?cb=20171130074159'"
onmouseout="this.src='https://vignette.wikia.nocookie.net/logopedia/images/2/28/Google_2015.svg/revision/latest?cb=20170804092955'">
</div>
The important part is position:relative on parent and position:absolute on second child, the rest are just some max-values to make sure they are resized on narrower screens and some centering (both vertical and horizontal) on parent.
A few more pointers:
neither draggable="false" or position:static are needed, as they're default values. But they're not wrong.
you also don't need z-index at all here, as any item is rendered above its preceding siblings, in case they overlap (except when one of them is positioned (has a set position value, other than static) and the other one is not, in which case the positioned one is on top.
There looks like there are a few issues here. I think this is what you are looking for.
For your div, give it a relative position. Then, for each image, give them an absolute position. At that point the images should sit ontop of each other and there positioning will be absolute to the div and not the body.
ex.
div {
position: relative;
}
.img1 {
position: absolute;
z-index: 1;
}
.img2 {
position: absolute;
z-index: 2;
}
<div class="parent" style="background-image:url('https://icdn2.digitaltrends.com/image/google-campus-hq-headquarters-home-offices-720x720.jpg?ver=1.jpg');">
<img class="image2" src="https://vignette.wikia.nocookie.net/logopedia/images/2/28/Google_2015.svg/revision/latest?cb=20170804092955" onmouseover="this.src='https://vignette.wikia.nocookie.net/logopedia/images/2/25/Google_2015_%28Black%29.svg/revision/latest?cb=20171130074159'"
onmouseout="this.src='https://vignette.wikia.nocookie.net/logopedia/images/2/28/Google_2015.svg/revision/latest?cb=20170804092955'">
</div>
Can you just add the picture as background for the div?

Block boundaries of complex shape via css+html

On the image above the triangle is outer block, and the main block have 'overflow: hidden'. During the animation part of the animated image is cropped. In the main block necessary boundaries of complex shape. Any ideas how is this possible? Requirement of browsers - top versions chrome or firefox.
example: http://jsfiddle.net/F7Cz9/
This one is a little complex and I don't have all the styling down yet but by using pseudo-elements on a wrapper to create the triangle above...you can do it.
The hover is there just to show the "overflow" working.
Codepen.io Demo
HTML
<div class="super-wrap">
<div class="imgwrapper">
<img src="http://lorempixel.com/output/city-q-c-350-100-8.jpg" alt="" />
</div>
</div>
CSS
.super-wrap {
width:700px;
margin: 50px auto 0;
padding-top: 50px;
border:1px solid grey;
}
.imgwrapper {
width:700px;
position: relative;
}
.imgwrapper img {
display: block;
margin-left: 0;
transition:margin-left 1s ease;
}
.super-wrap:hover img {
display: block;
margin-left: 50%;
}

a:hover image overflow issue

I'm creating a hover effect so that when someone mouse-over's on an image scan lines appear, but can't get the damn overlay image to be the same size as the image.
Take a look at this fiddle: http://jsfiddle.net/number8pie/wwmPL/
Here's the HTML:
<div class="container">
<a href="#">
<div class="overlay"></div>
<img src="http://www.mainlymunros.co.uk/images/green%20square.bmp" repeat>
</a>
</div>
Here's the CSS:
.container {
position: relative;
max-width: 200px;
}
img {
width: 100%;
position: relative;
z-index: 1;
padding: 7px;
border: 1px solid #333;
}
.overlay {
display: none;
position: absolute;
z-index: 5;
width: 100%;
height: 100%;
margin: 8px;
background: url(https://dl.dropbox.com/u/29825082/scanlines.png) repeat;
}
a:hover .overlay {
display: block;
}
If you hover over the green block you can see the scan lines overlap at the bottom, I want to remove this overlap.
The image is dynamic and changes size depending on the size of the browser size.
Anyone got any suggestions?
The problem is that you're giving it 100% height and 100% width but then you're giving it margin. You're telling it to be the exact size of it's containing a element, but then pushing it down a bit.
You need to add an extra container, remove the image's padding and border and assign that to the new container.
<a href="#">
<div class="image">
<div class="overlay"></div>
<img src="http://www.mainlymunros.co.uk/images/green%20square.bmp"/>
</div>
</a>
.container a {
display:block;
padding:7px;
border: 1px solid #333;
}
.image {
position:relative;
width:100%;
height:100%;
display:block;
}
img {
width: 100%;
position: relative;
z-index: 1;
}
.overlay {
display: none;
position:absolute;
z-index: 5;
width: 100%;
height: 100%;
background: url(https://dl.dropbox.com/u/29825082/scanlines.png) repeat;
}
Example: JSFiddle.
Your problem now is that your img isn't square. Being a rectangular image with greater width than height means it will fill 100% width but cut off part of the height. Make your image a square or give your overlay the same aspect ratio and this will work perfectly.
its padding property which creates overflow. so change the height of both image and .overlay
that will do.
fiddle :http://jsfiddle.net/wwmPL/2/
i hope this that solves your problem :)