If I hover over the image div, the text section will become from the bottom showing div shear in code my code is semple code very this is my code content button
If I hover over the image div, the text section will become from the bottom showing div shear in code my code is semple code very this is my code content button
.photo-album .common .details {
text-align: center;
position: absolute;
bottom: 15%;
left: 0;
right: 0;
transform: translateY(200%);
transition: .3s ease-in;
}
.photo-album .common .photo::after {
content: '';
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
height: 100%;
width: 100%;
background: #00000086;
transform: translateY(100%);
transition: .3s ease-in;
z-index: 8;
}
.photo-album .common .photo:hover.photo::after {
transform: translateY(0);
}
.photo-album .common .photo:hover.details {
transform: translateY(0);
}
<section class="photo-album">
<div class="common">
<div class="photo">
<div class="border-bottom border"></div>
<div class="border-left border"></div>
<img src="./images/ayon.jpg" alt="">
</div>
<div class="details">
<h1>Shorif Uddin</h1>
<p>Student of Programming Hero</p>
</div>
<div class="overlay"></div>
</div>
</section>
Related
I try to make an animation of an image from width 0% to 100%.
But there is a movement difference when I set the css style of an image in html.
If the image stye is set "width:100%" in html, the animation movement starting from top right corner.
If the image stye is not set, the animation movement starting from right to left.
What I need is set the image as width:100% in html and the animation movement from right to left.
Here is the demo link to
codepen : demo sample
.showVideoImage{
position: absolute;
width: 0%;
left: 100%;
transition: 0.5s;
}
.showVideoImage2{
position: absolute;
width: 0%;
left: 100%;
transition: 0.5s;
}
div.product-box:hover .showVideoImage
{
left: 0%;
width: 100%;
}
div.product-box2:hover .showVideoImage2
{
left: 0%;
width: 100%;
}
<div class="product-box">
<h2>hover me test1</h2>
<div class="showVideoImage" >
<img src="https://data.photo-ac.com/data/thumbnails/34/346a378b2e5b1bc0d8d999c811f8e6aa_w.jpeg" style="width:100%"/>
</div>
</div>
<div class="product-box2">
<h2>hover me test2</h2>
<div class="showVideoImage2" >
<img src="https://data.photo-ac.com/data/thumbnails/34/346a378b2e5b1bc0d8d999c811f8e6aa_w.jpeg" />
</div>
</div>
You need to set the width of the img itself not the parent tag.
.showVideoImage{
position: absolute;
left: 100%;
opacity:0;
transition: 1s;
}
div.product-box:hover > .showVideoImage
{
left: 0%;
opacity:1;
}
div.product-box:hover img
{
width:750px;
}
img{
width:0px;
}
<div class="product-box">
<h2>hover me test1</h2>
<div class="showVideoImage" >
<img src="https://data.photo-ac.com/data/thumbnails/34/346a378b2e5b1bc0d8d999c811f8e6aa_w.jpeg"/>
</div>
</div>
You can just remove with:0, the image already in-visible and all you have to do is to change left CSS attribute value:
.showVideoImage{
position: absolute;
width: 100%;
left: 100%;
transition: 0.5s;
}
.showVideoImage2{
position: absolute;
width: 100%;
left: 100%;
transition: 0.5s;
}
div.product-box:hover .showVideoImage
{
left: 0%;
}
div.product-box2:hover .showVideoImage2
{
left: 0%;
}
<div class="product-box">
<h2>hover me test1</h2>
<div class="showVideoImage" >
<img src="https://data.photo-ac.com/data/thumbnails/34/346a378b2e5b1bc0d8d999c811f8e6aa_w.jpeg" style="width:100%"/>
</div>
</div>
<div class="product-box2">
<h2>hover me test2</h2>
<div class="showVideoImage2" >
<img src="https://data.photo-ac.com/data/thumbnails/34/346a378b2e5b1bc0d8d999c811f8e6aa_w.jpeg" />
</div>
</div>
I have rewritten a book page flip animation based on Codrops to a more lightweight version with less JavaScript.
My animation runs as desired in Firefox (and Safari), but not in Chrome.
Clicking on the right half of the image for the next picture, Chrome does not show the picture on the flipping side. For demonstration purposes, I set background: red and created the div.helper-class-to-make-bug-visbile to make background: red visible. It only occurs the first time the picture flips. When I go back and flip again the animation is not lagging anymore. This is annoying, even the animation only lags on the first turn.
Demo: https://codepen.io/pizzabote/pen/xxxXmXN
How to fix this so the animation from the demo works in Chrome properly too (flipping the image the first time without lagging)? Or is this a bug in Chrome?
I'm using Chrome version 78.0.3904.87 (Official Build) (64-bit) on macOS Mojave. On Windows, the animation with this Chrome version does not work for me either.
HTML part:
<div class="container">
<div class="page" id="first">
<div class="back">
<div class="outer">
<div class="content">
<img src="img/1.jpg">
</div>
</div>
</div>
</div>
<div class="page" id="second">
<div class="front">
<div class="outer">
<div class="content">
<img src="img/1.jpg">
</div>
</div>
</div>
<div class="back" id="third">
<div class="outer">
<div class="content">
<div class="helper-class-to-make-bug-visbile">
<img src="img/2.jpg">
</div>
</div>
</div>
</div>
</div>
<div class="page" id="fourth">
<div class="front">
<div class="outer">
<div class="content">
<img src="img/2.jpg">
</div>
</div>
</div>
</div>
</div>
CSS part:
.container {
width: 400px;
height: 300px;
position: relative;
z-index: 100;
-webkit-perspective: 1300px;
perspective: 1300px;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.page {
position: absolute;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-transition-property: -webkit-transform;
transition-property: transform;
width: 50%;
height: 100%;
left: 50%;
-webkit-transform-origin: left center;
transform-origin: left center;
}
#first,
#first .back {
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
}
#first {
z-index: 102;
}
#second {
z-index: 103;
transition: transform 0.8s ease-in-out;
}
#third .content {
width: 400px;
}
#fourth {
z-index: 101;
}
.page > div,
.outer,
.content,
.helper-class-to-make-bug-visbile {
position: absolute;
height: 100%;
width: 100%;
top: 0;
left: 0;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.page > div {
width: 100%;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.back {
-webkit-transform: rotateY(-180deg);
transform: rotateY(-180deg);
}
.outer {
width: 100%;
overflow: hidden;
z-index: 999;
}
/* problematic class: `.content` */
.content {
width: 200%;
background: red;
}
.front .content {
left: -100%;
}
So what's happening?
Backface Visibility
This is happening because you have backface-visibility in .page > div, .outer, .content, .helper-class-to-make-bug-visbile set to hidden. A simple set to visible will fix it.
Here is the functioning code:
let prev = document.getElementById("prev");
let next = document.getElementById("next");
prev.addEventListener("click", prevImg);
next.addEventListener("click", nextImg);
let second = document.getElementById('second');
function prevImg() {
second.style.msTransform = "rotateY(0deg)";
second.style.webkitTransform = "rotateY(0deg)";
second.style.transform = "rotateY(0deg)";
}
function nextImg() {
second.style.msTransform = "rotateY(-180deg)";
second.style.webkitTransform = "rotateY(-180deg)";
second.style.transform = "rotateY(-180deg)";
}
body {
margin: 4em;
}
.container {
width: 400px;
height: 300px;
position: relative;
z-index: 100;
-webkit-perspective: 1300px;
perspective: 1300px;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.page {
position: absolute;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-transition-property: -webkit-transform;
transition-property: transform;
width: 50%;
height: 100%;
left: 50%;
-webkit-transform-origin: left center;
transform-origin: left center;
}
#first,
#first .back {
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
}
#first {
z-index: 102;
}
#second {
z-index: 103;
transition: transform 0.8s ease-in-out;
}
#third .content {
width: 400px;
}
#fourth {
z-index: 101;
}
.page > div,
.outer,
.content,
.helper-class-to-make-bug-visbile {
position: absolute;
height: 100%;
width: 100%;
top: 0;
left: 0;
-webkit-backface-visibility: visible;
backface-visibility: visible;
}
.page > div {
width: 100%;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.back {
-webkit-transform: rotateY(-180deg);
transform: rotateY(-180deg);
}
.outer {
width: 100%;
overflow: hidden;
z-index: 999;
}
/* problematic class: `.content` */
.content {
width: 200%;
background: red;
}
.front .content {
left: -100%;
}
/* controls */
#prev, #next {
position: absolute;
width: 50%;
height: 100%;
z-index: 999;
}
#prev:hover, #next:hover {
background: rgba(0,0,0,0.05);
cursor: pointer;
}
#prev {
top: 0;
left: 0;
}
#next {
top: 0;
left: 50%;
}
<div class="container">
<div class="page" id="first">
<div class="back">
<div class="outer">
<div class="content">
<img src="https://tympanus.net/Development/BookBlock/images/demo1/1.jpg">
</div>
</div>
</div>
</div>
<div class="page" id="second">
<div class="front">
<div class="outer">
<div class="content">
<img src="https://tympanus.net/Development/BookBlock/images/demo1/1.jpg">
</div>
</div>
</div>
<div class="back" id="third">
<div class="outer">
<div class="content">
<div class="helper-class-to-make-bug-visbile">
<img src="https://tympanus.net/Development/BookBlock/images/demo1/2.jpg">
</div>
</div>
</div>
</div>
</div>
<div class="page" id="fourth">
<div class="front">
<div class="outer">
<div class="content">
<img src="https://tympanus.net/Development/BookBlock/images/demo1/2.jpg">
</div>
</div>
</div>
</div>
<div id="prev"></div>
<div id="next"></div>
</div>
Run that snippet to see the problem erased from the face of the Universe!
Is there any way of making this overlay more responsive? As in, making the overlay not cut off words, or go outside the image when resolution changes?
To further clarify: I am having three images next to each other in a row, per the W3CSS framework I am using, with three images under that, etc. Each image has an overlay with text links that direct to other pages, as shown in the example below. My only issue is responsiveness. As I want the images, and the overlays, to be responsive to screen size changes and resolution.
Thank you!
.container {
position: relative;
width: 50%;
}
.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: #008CBA;
}
.container:hover .overlay {
opacity: 1;
}
.text {
color: white;
font-size: 15px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<link href="https://www.w3schools.com/w3css/4/w3.css" rel="stylesheet"/>
<div class="w3-row-padding">
<div class="w3-third w3-container w3-margin-bottom">
<div class="container">
<img src="https://www.google.com/images/branding/product/ico/googleg_lodp.ico" alt="Google" style="height:300px;width:400px" class="w3-hover-opacity">
<div class="overlay">
<div class="text">
Google Sample1<br>
GoogleSample2<br>
</div>
</div>
</div>
<div class="w3-container w3-white" style="height:50px;width:400px">
<h3>Example 1</h3>
</div>
</div>
</div>
To make sure, that your image is the same width as parent, you better use not only width = 100% property, but min-width = 100% and max-width = 100% too. If you want to keep the dimensions of image, you also should point height = auto, but in your case it should be height = auto !important. And for breaking long words in overlay, i have added the following rules:
overflow-wrap: break-word;
word-wrap: break-word;
word-break: break-all;
word-break: break-word;
hyphens: auto;
Here is the working snippet:
.container {
position: relative;
width: 50%;
}
.image {
display: block;
width: 100%;
min-width: 100%;
max-width: 100%;
height: auto !important;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: #008CBA;
overflow-wrap: break-word;
word-wrap: break-word;
word-break: break-all;
word-break: break-word;
hyphens: auto;
}
.container:hover .overlay {
opacity: 1;
}
.text {
color: white;
font-size: 15px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<div class="w3-row-padding">
<div class="w3-third w3-container w3-margin-bottom">
<div class="container">
<img src="https://www.google.com/images/branding/product/ico/googleg_lodp.ico" alt="Google" style="height:300px;width:400px" class="w3-hover-opacity image"></a>
<div class="overlay">
<div class="text">
Google Sample1<br>
GoogleSample2<br>
</div>
</div>
</div>
<div class="w3-container w3-white" style="height:50px;width:400px">
<h3>Example 1</h3>
</div>
</div>
Background-size:cover is your friend when it comes to responsive images. With the image being the background, cover will position it so it fits the width/height automatically and will resize in the other direction that it doesn't fit so that it keeps the ratio. That way the image looks like it stays the same size the whole time, but it's responsive and doesn't get distorted.
.container {
position: relative;
width: 0%;
}
.w3-third{
background-image:url('http://www.fillmurray.com/200/300');
background-size:cover;
background-position:center center;
height:300px;
width:33.333%;
float:left;
display:block;
position:relative;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
opacity: 0;
transition: .5s ease;
background-color: #008CBA;
}
.w3-container:hover .overlay {
opacity: 1;
}
.text {
color: white;
font-size: 15px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<div class="w3-row-padding">
<div class="w3-third w3-container w3-margin-bottom">
<div class="overlay">
<div class="text">
Google Sample1<br>
Google Sample2<br>
</div>
</div>
</div>
<div class="w3-third w3-container w3-margin-bottom">
<div class="overlay">
<div class="text">
Google Sample1<br>
Google Sample2<br>
</div>
</div>
</div>
<div class="w3-third w3-container w3-margin-bottom">
<div class="overlay">
<div class="text">
Google Sample1<br>
Google Sample2<br>
</div>
</div>
</div>
</div>
I'm trying to remove the automatically generated container margin around this image. Below is the code I used to produce it. You can view the website here. I tried to add a margin and padding item to the body element, but it didn't resolve the issue.
.container {
position: relative;
width: 240px;
height: 240px;
}
.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: #008CBA;
}
.container:hover .overlay {
opacity: 0.85;
}
.text {
color: white;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<div class="container">
<img src="./img/headshots/Exec_DMoon.jpg" width="240" height="240" alt="Photo of David Moon, Assistant Vice President for Financial Affairs" class="image">
<div class="overlay">
<div class="text"><b>David Moon</b> Assistant Vice President for Financial Affairs, <a class="usa-external_link" target="_blank" href="mailto:davidmoon826#gwmail.gwu.edu">Email</a></div>
</div>
</div>
This is the desired output:
What am I doing wrong?
The easiest fix for this, imo: wrap the items you want in a grid in a div and give the div display: flex and flex-wrap: wrap. Good luck!
Well, just add float: left to .container
(to achieve what you show under "this is the desired output")
The answer from Johannes almost worked, but it caused issues where text would reposition itself into the open gaps (see image below), instead of formatting below all the images.
The solution was to use display: inline-block; in .container, as Adrian recommended.
<!DOCTYPE html>
<html>
<head>
<style>
.container {
position: relative;
width: 50%;
height: 50%;
display: inline-block;
}
.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: #008CBA;
}
.container:hover .overlay {
opacity: 0.8;
}
.text {
color: white;
font-size: 25px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<h2>Fade in Overlay</h2>
<p>Hover over the image to see the effect.</p>
<div class="container">
<img src="img_avatar.png" alt="Avatar" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
<div class="container">
<img src="img_avatar.png" alt="Avatar" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
<div class="container">
<img src="img_avatar.png" alt="Avatar" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
<h2>Fade in Overlay</h2>
<p>Hover over the image to see the effect.</p>
</body>
</html>
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.