I create a slider with some logos, but the animation doesn't start. I create it with only css but it remains blocked. I check few time the code but I can find the answer.
The slider should scroll and change the logo, but it doesn't work.
I think that it could be also created with javascript but I'm not sure how to do it.
Can someone help me?
.slider {
width: 960px;
height: 100px;
overflow: hidden;
position: relative;
margin: auto;
}
.slider::before,
.slider::after {
content: "";
position: absolute;
width: 200px;
height: 100px;
background: linear-gradient(to right, width 0%, rgba(255, 255, 255, 0) 100%);
z-index: 2;
}
.slider::before {
top: 0;
left: 0;
}
.slider::after {
top: 0;
right: 0;
transform: rotateZ(180deg);
}
.slider .slide img {
width: 200px;
height: 100px;
}
.slider .slider-track {
display: flex;
width: calc(200px * 20);
animation: scroll 4s ease 3s infinite linear;
}
#keyframes scroll {
0% {
transform: translateX(0);
}
100% {
transform: translateX(calc(-200px * 10));
}
}
<div class="slider">
<div class="slider-track">
<div class="slide">
<img src="./1.png">
</div>
<div class="slide">
<img src="./2.png">
</div>
<div class="slide">
<img src="./3.png">
</div>
<div class="slide">
<img src="./4.png">
</div>
<div class="slide">
<img src="./5.png">
</div>
<div class="slide">
<img src="./6.png">
</div>
<div class="slide">
<img src="./7.png">
</div>
<div class="slide">
<img src="./8.png">
</div>
<div class="slide">
<img src="./9.png">
</div>
<div class="slide">
<img src="./10.png">
</div>
</div>
</div>
Your animation property is wrong.
use these properties instead. This is more readable and it makes it easier to avoid similar mistakes:
animation-name
animation-duration
animation-timing-function
animation-delay
animation-iteration-count
animation-direction
animation-fill-mode
animation-play-state
https://www.w3schools.com/cssref/css3_pr_animation.asp
.slider {
width: 960px;
height: 100px;
overflow: hidden;
position: relative;
margin: auto;
}
.slider::before,
.slider::after {
content: "";
position: absolute;
width: 200px;
height: 100px;
background: linear-gradient(to right, width 0%, rgba(255, 255, 255, 0) 100%);
z-index: 2;
}
.slider::before {
top: 0;
left: 0;
}
.slider::after {
top: 0;
right: 0;
transform: rotateZ(180deg);
}
.slider .slide img {
width: 200px;
height: 100px;
}
.slider .slider-track {
display: flex;
width: calc(200px * 20);
animation: scrolll 4s ease;
}
#keyframes scrolll {
0% {
transform: translateX(0);
}
100% {
transform: translateX(calc(-200px * 10));
}
}
<div class="slider">
<div class="slider-track">
<div class="slide">
<img src="./1.png">
</div>
<div class="slide">
<img src="./2.png">
</div>
<div class="slide">
<img src="./3.png">
</div>
<div class="slide">
<img src="./4.png">
</div>
<div class="slide">
<img src="./5.png">
</div>
<div class="slide">
<img src="./6.png">
</div>
<div class="slide">
<img src="./7.png">
</div>
<div class="slide">
<img src="./8.png">
</div>
<div class="slide">
<img src="./9.png">
</div>
<div class="slide">
<img src="./10.png">
</div>
</div>
</div>
Related
If I am using a transform scale is there a way to keep the object fit image using cover from stretching?
Here is my code
div.category {
width: 80%;
height: 150px;
margin: 20px;
position: relative;
overflow: hidden;
}
img {
width: 100%;
transition: transform 0.35s;
object-fit:cover;
}
div.category:hover {
transform:scalex(1.2)
}
html
<div>
<div class="category">
<img src="http://www.4freephotos.com/images/batch/Elephant-dusting674.jpg" />
</div>
<div class="category">
<img src="http://www.4freephotos.com/images/batch/Bananas-and-kiwi-221.jpg" />
</div>
<div class="category">
<img src="http://placehold.it/1200x950&text=1200x950+-+Category+3+-" />
</div>
</div>
Here is a fiddle explaining what I mean:
http://jsfiddle.net/n1x5ak2t/
I would love if the image just scaled up to fit the new div width without distorting.
Consider a different animation. Here is an idea using clip-path
div.category {
width: 80%;
height: 150px;
margin: 20px;
position: relative;
overflow: hidden;
transition: 0.35s;
clip-path:inset(0 10%);
}
img {
width: 100%;
object-fit: cover;
transition: 0.35s;
}
div.category:hover {
clip-path:inset(0 0%);
}
<div>
<div class="category">
<img src="http://www.4freephotos.com/images/batch/Elephant-dusting674.jpg" />
</div>
<div class="category">
<img src="http://www.4freephotos.com/images/batch/Bananas-and-kiwi-221.jpg" />
</div>
<div class="category">
<img src="http://placehold.it/1200x950&text=1200x950+-+Category+3+-" />
</div>
</div>
div.category:hover img {
transform:scalex(1.2)
}
https://jsfiddle.net/7d31Ln0f/
Here is a different approach.
div.category {
width: 80%;
height: 150px;
margin: 20px;
position: relative;
overflow: hidden;
}
img {
width: 100%;
transition: transform 0.35s;
object-fit: cover;
}
div.category:hover {
transform:scalex(1.2)
}
div.category:hover img {
transform:scale(1.2)
}
<div>
<div class="category">
<img src="http://www.4freephotos.com/images/batch/Elephant-dusting674.jpg" />
</div>
<div class="category">
<img src="http://www.4freephotos.com/images/batch/Bananas-and-kiwi-221.jpg" />
</div>
<div class="category">
<img src="http://placehold.it/1200x950&text=1200x950+-+Category+3+-" />
</div>
</div>
I would like to display images with some description on them, that will be overlayed when hover. I've got something like this:
<div class="container-fluid">
<div class="row">
<div class="product-item col-md-4 col-sm-6 col-xs-12 p-3">
<div class="product-container">
<img src="images/img.png" class="product-img" alt="">
<p class="product-descr">Some description</p>
</div>
</div>
</div>
</div>
Now I need to add some classes (product-item, product-container, product-img, product-desc) to get it working. But I've tried many combinations and still have description below the image (even if the description overlay goes in the right place). And text makes the container going out of the bottom of image and the background of this container is visible.
At present my styles look like this:
.product-item {
position: relative;
}
.product-container {
background:red;
position: relative;
width:100%;
}
.product-img {
position: relative;
width: 100%;
#include hover-focus {
opacity: .5;
}
}
.product-overlay {
position: relative;
&:after {
position: absolute;
content: "";
background: #FFF;
top: -25px;
left: 0;
width: 100%;
height: 25px;
opacity: .7;
z-index:10;
}
}
Any help appreciated. Thank you.
You could position your overlay absolutely and move it out of the way with transform: translateY(). On hover you move it back in. Is this the effect you wanted to achieve?
Here is a CodePen to play with: https://codepen.io/Sixl/pen/bOdwaZ?editors=1100
.product-item {
position: relative;
}
.product-container {
background: #000;
position: relative;
width: 100%;
overflow: hidden;
}
.product-container .product-description {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
background-color: rgba(0, 0, 0, 0.6);
text-align: right;
padding: 0.2em 0.4em 0.2em;
-webkit-transform: translateY(101%);
transform: translateY(101%);
transition: -webkit-transform 200ms ease-in-out;
transition: transform 200ms ease-in-out;
transition: transform 200ms ease-in-out, -webkit-transform 200ms ease-in-out;
}
.product-container:hover .product-description {
-webkit-transform: translateY(0);
transform: translateY(0);
}
.product-img {
display: block;
max-width: 100%;
height: auto;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="row">
<div class="product-item col-md-4 col-sm-6 col-xs-12 p-1">
<a href="#">
<figure class="product-container">
<img class="product-img" alt="" src="https://picsum.photos/800/450?image=20">
<figcaption class="product-description">Some description</figcaption>
</figure>
</a>
</div>
<div class="product-item col-md-4 col-sm-6 col-xs-12 p-2">
<a href="#">
<figure class="product-container">
<img class="product-img" alt="" src="https://picsum.photos/800/450?image=21">
<figcaption class="product-description">Some description</figcaption>
</figure>
</a>
</div>
<div class="product-item col-md-4 col-sm-6 col-xs-12 p-3">
<a href="#">
<figure class="product-container">
<img class="product-img" alt="" src="https://picsum.photos/800/450?image=22">
<figcaption class="product-description">Some description</figcaption>
</figure>
</a>
</div>
<div class="product-item col-md-4 col-sm-6 col-xs-12 p-4">
<a href="#">
<figure class="product-container">
<img class="product-img" alt="" src="https://picsum.photos/800/450?image=23">
<figcaption class="product-description">Some description</figcaption>
</figure>
</a>
</div>
<div class="product-item col-md-4 col-sm-6 col-xs-12 p-5">
<a href="#">
<figure class="product-container">
<img class="product-img" alt="" src="https://picsum.photos/800/450?image=24">
<figcaption class="product-description">Some description</figcaption>
</figure>
</a>
</div>
<div class="product-item col-md-4 col-sm-6 col-xs-12 p-6">
<a href="#">
<figure class="product-container">
<img class="product-img" alt="" src="https://picsum.photos/800/450?image=25">
<figcaption class="product-description">Some description</figcaption>
</figure>
</a>
</div>
</div>
</div>
Here something concerning the position of your description, but you should better describe what you want :
Bootply : https://www.bootply.com/blEmsHAYJ1
CSS:
.product-item {
position: relative;
}
.product-container {
background:red;
position: relative;
width:100%;
}
.product-overlay {
position: relative;
}
.product-overlay:after {
position: absolute;
content: "";
background: #FFF;
top: -25px;
left: 0;
width: 100%;
height: 25px;
opacity: .7;
z-index:10;
}
.product-img {
position: relative;
width: 100%;
}
.product-img:hover {
opacity: .5;
}
.product-descr{
position: absolute;
bottom: 0;
display: block;
width: 100%;
margin: 0;
text-align: center;
}
I have a series of images each with his own overlay. How can I have them aligned like inline-blocks? I tried adding adding display: inline-block;to .image-wrapper but the images are always all positioned in the top left corner of the div.container (Here is a jsfiddle).
Here are the html and css
.container {
position: relative;
}
.image-wrapper {
position: relative;
display: inline-block;
}
.tweetty {
position: absolute;
overflow: auto;
top: 0;
left: 0;
}
.image-vest {
position: absolute;
top: 0;
left: 0;
background-color: #00f;
width: 220px;
height: 300px;
opacity: 0.4;
color: #fff;
}
<div class="container">
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-one</div>
</div>
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-two</div>
</div>
</div>
EDIT:
revised css with dfsq suggestion to remove position:absolute; from .tweetty.
Quoting dfsq comment:
"Elements with position absolute don't contribute to the width and height of their parent container. So the image-wrapper divs just collapse as if they were empty if all children have position:absolute; "
.container {
position: relative;
}
.image-wrapper {
position: relative;
display: inline-block;
}
.tweetty {
overflow: auto;
top: 0;
left: 0;
}
.image-vest {
position: absolute;
top: 0;
left: 0;
background-color: #00f;
width: 220px;
height: 300px;
opacity: 0.4;
color: #fff;
}
<div class="container">
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-one</div>
</div>
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-two</div>
</div>
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-three</div>
</div>
</div>
I fiddled with the fiddle, and this seems to work. removed all the positioning from all but the vest. Used the inline-block display mode. Set top to -300px, and also the bottom-margin, otherwise you get a gap below the images.
.container {
/* position:relative;*/
}
.image-wrapper {
/* position: relative;*/
display: inline-block;
}
.tweetty {
/* position:absolute;
overflow:auto;
top:0;
left:0;*/
}
.image-vest {
position:relative;
top:-300px;
margin-bottom: -300px;
left:0;
background-color:#00f;
width:220px;
height:300px;
opacity:0.4;
color:#fff;
}
<div class="container">
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-one</div>
</div>
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-two</div>
</div>
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-three</div>
</div>
</div>
(here's the JSFiddle version)
Can't seem to figure out how to get these buttons to align both vertically and horizontally
Code in jsfiddle
CSS
#font-face {
font-family: "HemiHead";
src: url("../../fonts/hemi_head_bd_it.otf");
src: local("hemi_head_bd_it"),
url("../../fonts/hemi_head_bd_it.otf") format("opentype"),
}
/* entire container, keeps perspective */
.flip-container {
perspective: 1000px;
}
/* flip the pane when hovered */
.flip-container:hover .flipper, .flip-container.hover .flipper {
transform: rotateY(180deg);
}
.flip-container, .front, .back {
width: 200px;
height: 200px;
}
/* flip speed goes here */
.flipper {
transition: 0.6s;
transform-style: preserve-3d;
position: relative;
}
/* hide back of pane during swap */
.front, .back {
backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
}
/* front pane, placed above back */
.front {
z-index: 2;
/* for firefox 31 */
transform: rotateY(0deg);
}
/* back, initially hidden pane */
.back {
transform: rotateY(180deg);
}
.inlineWrapper {
float: left;
padding: 5px;
}
html
<div id="background">
<div class="inlineWrapper">
<div class="flip-container">
<div class="flipper">
<div class="front">
<img src="~/Content/Images/SquareTest.png" width="200" height="200" />
</div>
<div class="back">
<img src="~/Content/Images/SquareTest.png" width="200" height="200" />
</div>
</div>
</div>
</div>
<div class="inlineWrapper">
<div class="flip-container">
<div class="flipper">
<div class="front">
<img src="~/Content/Images/SquareTest.png" width="200" height="200" />
</div>
<div class="back">
<img src="~/Content/Images/SquareTest.png" width="200" height="200" />
</div>
</div>
</div>
</div>
<div class="inlineWrapper">
<div class="flip-container">
<div class="flipper">
<div class="front">
<img src="~/Content/Images/SquareTest.png" width="200" height="200" />
</div>
<div class="back">
<img src="~/Content/Images/SquareTest.png" width="200" height="200" />
</div>
</div>
</div>
</div>
</div>
You need to:
Wrap div.inlineWrapper into a div.container.
Add width: 630px, height: 210px, transform: translate(-50%, -50%), left: 50% and top: 50% to .container.
Add a width: 588px and position: relative to #backgruond
And this will center all your buttons vertically and horizontally.
Demo on dabblet
HTML:
<div id="background">
<div class="container">
<div class="inlineWrapper">
<div class="flip-container">
<div class="flipper">
<div class="front">
<img src="http://dummyimage.com/100x100/000/fff" width="200" height="200" />
</div>
<div class="back">
<img src="http://dummyimage.com/100x100/000/fff" width="200" height="200" />
</div>
</div>
</div>
</div>
<div class="inlineWrapper">
<div class="flip-container">
<div class="flipper">
<div class="front">
<img src="http://dummyimage.com/100x100/000/fff" width="200" height="200" />
</div>
<div class="back">
<img src="http://dummyimage.com/100x100/000/fff" width="200" height="200" />
</div>
</div>
</div>
</div>
<div class="inlineWrapper">
<div class="flip-container">
<div class="flipper">
<div class="front">
<img src="http://dummyimage.com/100x100/000/fff" width="200" height="200" />
</div>
<div class="back">
<img src="http://dummyimage.com/100x100/000/fff" width="200" height="200" />
</div>
</div>
</div>
</div>
</div>
</div>
CSS:
#font-face {
font-family:"HemiHead";
src: url("../../fonts/hemi_head_bd_it.otf");
src: local("hemi_head_bd_it"), url("../../fonts/hemi_head_bd_it.otf") format("opentype"),
}
/* entire container, keeps perspective */
.flip-container {
perspective: 1000px;
}
/* flip the pane when hovered */
.flip-container:hover .flipper, .flip-container.hover .flipper {
transform: rotateY(180deg);
}
.flip-container, .front, .back {
width: 200px;
height: 200px;
}
/* flip speed goes here */
.flipper {
transition: 0.6s;
transform-style: preserve-3d;
position: relative;
}
/* hide back of pane during swap */
.front, .back {
backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
}
/* front pane, placed above back */
.front {
z-index: 2;
/* for firefox 31 */
transform: rotateY(0deg);
}
/* back, initially hidden pane */
.back {
transform: rotateY(180deg);
}
.inlineWrapper {
float: left;
padding: 5px;
}
.container {
position: relative;
width: 630px;
height: 210px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
#background {
height: 588px;
position: relative;
}
I have a 3d cube rotation, that happens on hover. Everything works fine except one thing. When you roll over and the cube rotates showing a new side with text....the text is backwards, not sure why this is happening. I have a JS fiddle set up, and any help I can get on this would be great.
http://jsfiddle.net/c3ewZ/6/
html:
This is back
<div class='box-scene col-xs-12 col-sm-3'>
<div class='box'>
<div class='front face'></div>
<div class="side face">
<p>This is back</p>
</div>
</div>
</div>
<div class='box-scene col-xs-12 col-sm-3'>
<div class='box'>
<div class='front face'></div>
<div class="side face">
<p>This is back</p>
</div>
</div>
</div>
<div class='box-scene col-xs-12 col-sm-3'>
<div class='box'>
<div class='front face'></div>
<div class="side face">
<p>This is back</p>
</div>
</div>
</div>
css
body {
margin:0px;
padding:0px;
}
.box-scene {
-webkit-perspective: 700;
height: 180px;
float:left;
z-index: 999;
padding:0px !important;
}
.box-scene:hover .box {
-webkit-transform: rotateY(90deg);
}
.box {
width: 100%;
height: 100%;
position: relative;
-webkit-transform-style: preserve-3d;
-webkit-transition: all 0.4s ease-out;
-webkit-transform-origin: 90px 90px -90px;
}
.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: 0px;
}
JS
var resizer = function () {
var width = parseInt($(".box-scene").css("width"));
$(".box").css("-webkit-transform-origin", "center center -" + width / 2 + "px");
};
resizer();
$(window).resize(function () {
resizer();
});
Rotating the panel the other way will fix the mirror imaging of the text.
.box-scene:hover .box {
-webkit-transform: rotateY(-90deg);
}