Adding text next to slideshow images - html

this is a code I modified it a little bit to make a simple slideshow with images using only HTML and CSS:
(This is a part of the code to see it all please click on demo)
Code:
.slideshow {
width: 800px;
margin: 0 auto;
overflow: hidden;
border: solid 1px white;
}
.slideshow-container {
width: 2500px;
font-size: 0;
transition: 1s ease;
height: 225px;
}
#keyframes slide {
0% {
transform: translateX(0%);
}
12.5% {
transform: translateX(0%);
}
25% {
transform: translateX(-25%);
}
37.5% {
transform: translateX(-25%);
}
50% {
transform: translateX(-50%);
}
62.5% {
transform: translateX(-50%);
}
75% {
transform: translateX(-75%);
}
87.5% {
transform: translateX(-75%);
}
99% {
transform: translateX(-75%);
}
100% {
transform: translateX(0);
}
}
<section class="slideshow">
<div class="slideshow-container slide">
<img src="http://placeimg.com/625/225/any" />
<img src="http://placeimg.com/625/225/animals" />
<img src="http://placeimg.com/625/225/arch" />
</div>
</section>
demo
I want to add a text next to each image, so in the frame I will have half of it image and the other half text.
How can I achieve that?

You will wrap your image and text part into a .item div.
Apply display:flex to parent .slideshow-container to set .item in a row.
Then just apply width:50% to your img and .caption div to align them half of the screen
Also changed your animation animation partition values according to 3 items in a row
Fiddle Link
Stack Snippet
/*general styles*/
body {
padding: 3em;
background-color: #ccc;
}
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
/*slideshow styles*/
.slideshow {
width: 800px;
margin: 0 auto;
overflow: hidden;
border: solid 1px white;
}
.item {
display: flex;
width: 800px;
align-items: center;
}
.slideshow-container {
width: 2400px;
transition: 1s ease;
display: flex;
}
.slideshow-container:hover {
animation-play-state: paused;
}
.slide {
animation: slide 24s ease infinite;
}
#keyframes slide {
0% {
transform: translateX(0%);
}
25% {
transform: translateX(0);
}
37.5% {
transform: translateX(-33.333%);
}
62.5% {
transform: translateX(-33.333%);
}
75% {
transform: translateX(-66.667%);
}
99% {
transform: translateX(-66.667%);
}
100% {
transform: translateX(0);
}
}
.item img {
width: 50%
}
.item .caption {
width: 50%
}
<!--hovering over the images will pause the slideshow -->
<section class="slideshow">
<div class="slideshow-container slide">
<div class="item">
<img src="http://placeimg.com/625/225/any" />
<div class="caption">Text</div>
</div>
<div class="item">
<img src="http://placeimg.com/625/225/animals" />
<div class="caption">Text</div>
</div>
<div class="item">
<img src="http://placeimg.com/625/225/arch" />
<div class="caption">Text</div>
</div>
</div>
</section>

Related

Is there a way that I can make the second animation not get overwritten?

So I've tried separating the animations with a comma and having them on the same transform but it still doesn't work.
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
html, body {
width: 100%;
height: 100%;
}
.container {
width: 100%;
height: 100%;
background: silver;
display: flex;
justify-content: center;
align-items: center;
}
.box {
width: 20%;
height: 20%;
background-color: pink;
transform: rotate(0deg) translatey(0px);
animation: wavy 3s linear infinite alternate,
float 3s linear infinite alternate;
}
#keyframes wavy {
0% {
transform: rotate(0deg);
}
50% {
transform: rotate(-10deg);
}
100% {
transform: rotate(10deg);
}
}
#keyframes float {
0% {
transform: translatey(0px);
}
50% {
transform: translatey(-20px);
}
100% {
transform: translatey(0px);
}
}
<div class="container">
<div class="box"></div>
</div>
And here's a link to the codepen:
https://codepen.io/FaroukHamadi/pen/OJOWWKW
Yes - add an id to the div and set that animation on the specified id. For your example, I called it #box
EDIT ~ the id solution I had previously worked flawlessly UNLESS there are two transforms being used in the keyframe which is your case. What I would suggest is just combining the two animations into one animation and using more % increments. So instead of 0, 50, and 100, you can use 0, 25, 50, 75, 100 - to combine the two and have it seem like they are "alternating"
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
html, body {
width: 100%;
height: 100%;
}
.container {
width: 100%;
height: 100%;
background: silver;
display: flex;
justify-content: center;
align-items: center;
}
.box {
width: 20%;
height: 20%;
background-color: pink;
transform: rotate(0deg) translatey(0px);
animation: wavy-float 3s linear infinite alternate;
}
#keyframes wavy-float {
0% {
transform: rotate(0deg):
}
25% {
transform: rotate(-20deg);
}
50% {
transform: translateY(-20px);
}
75% {
transform: rotate(20deg);
}
100% {
transform: translateY(20px)
}
}
<div class="container">
<div class="box"></div>
</div>

Transition animation with CSS

I am trying to implement image transition in slide show. I have 4 rectangular boxes fit in a div container. Each box need to disappear the part that is coming into another box area after intersecting with another box as they move. At 100%, each box need to disappear completely.
#keyframes testAnimateOne {
0% {
transform: rotate(0);
transform-origin: bottom right;
opacity: 1;
}
100% {
transform-origin: bottom right;
transform: rotate(90deg);
}
}
#keyframes testAnimateTwo {
0% {
transform: rotate(0);
transform-origin: top right;
opacity: 1;
}
100% {
transform-origin: top right;
transform: rotate(-90deg);
}
}
#keyframes testAnimateThree {
0% {
transform: rotate(0);
transform-origin: bottom left;
opacity: 1;
}
100% {
transform-origin: bottom left;
transform: rotate(-90deg);
}
}
#keyframes testAnimateFour {
0% {
transform-origin: top left;
transform: rotate(0);
opacity: 1;
}
100% {
transform-origin: top left;
transform: rotate(90deg);
}
}
.layer1 {
width:50%;
height: 43px;
position: absolute;
background-color: black;
animation-name: testAnimateOne;
animation-duration: 5s;
}
.layer2 {
margin-top: 30%;
width: 50%;
height: 43px;
position: absolute;
background-color:black;
animation-name: testAnimateTwo;
animation-duration: 5s;
}
.layer3 {
width: 50%;
height: 50%;
margin-left: 50%;
position: absolute;
background-color: black;
animation-name: testAnimateThree;
animation-duration: 5s;
}
.layer4 {
margin-top: 30%;
margin-left: 50%;
width: 50%;
height: 50%;
position: absolute;
background-color: black;
animation-name: testAnimateFour;
animation-duration: 5s;
}
.container {
width: 140px;
height: 86px;
position: relative;
display: block;
}
<div class="container">
<div class="layer1"></div>
<div class="layer2"></div>
<div class="layer3"></div>
<div class="layer4"></div>
</div>
How is that possible? please help
You can hide the layers completely at the end of the animation by wrapping each in a container and giving those containers the property overflow: hidden so that the layer does not come out on the other side.
Make sure also to apply the sizing and positioning rules to the containers and then have the layers just fill their container completely, have color, and have the animation.
#keyframes testAnimateOne {
0% {
transform: rotate(0);
transform-origin: bottom right;
opacity: 1;
}
100% {
transform-origin: bottom right;
transform: rotate(90deg);
}
}
#keyframes testAnimateTwo {
0% {
transform: rotate(0);
transform-origin: top right;
opacity: 1;
}
100% {
transform-origin: top right;
transform: rotate(-90deg);
}
}
#keyframes testAnimateThree {
0% {
transform: rotate(0);
transform-origin: bottom left;
opacity: 1;
}
100% {
transform-origin: bottom left;
transform: rotate(-90deg);
}
}
#keyframes testAnimateFour {
0% {
transform-origin: top left;
transform: rotate(0);
opacity: 1;
}
100% {
transform-origin: top left;
transform: rotate(90deg);
}
}
.container {
width: 140px;
height: 86px;
position: relative;
display: block;
}
.layer {
width: 100%;
height: 100%;
background-color: black;
animation-duration: 5s;
animation-fill-mode: both;
}
.layer1-container {
width: 50%;
height: 43px;
position: absolute;
top: 0;
left: 0;
overflow: hidden;
}
.layer1-container .layer {
animation-name: testAnimateOne;
}
.layer2-container {
width: 50%;
height: 43px;
position: absolute;
bottom: 0;
left: 0;
overflow: hidden;
}
.layer2-container .layer {
animation-name: testAnimateTwo;
}
.layer3-container {
width: 50%;
height: 50%;
position: absolute;
top: 0;
right: 0;
overflow: hidden;
}
.layer3-container .layer {
animation-name: testAnimateThree;
}
.layer4-container {
width: 50%;
height: 50%;
position: absolute;
bottom: 0;
right: 0;
overflow: hidden;
}
.layer4-container .layer {
animation-name: testAnimateFour;
}
<div class="container">
<div class="layer1-container">
<div class="layer"></div>
</div>
<div class="layer2-container">
<div class="layer"></div>
</div>
<div class="layer3-container">
<div class="layer"></div>
</div>
<div class="layer4-container">
<div class="layer"></div>
</div>
</div>
Wrapping the divs in a container then setting that to overflow: hidden will result in the rotating divs being cut off whenever they would go outside the container. However, if you want the rotating bits to visually jut out from the container, it's a little more complicated.
For some reason, the specs say that when one overflow direction is hidden, the other must either be hidden or auto. This results in us needing to use hacky methods to get the required result. In this case, it's using padding and negative margins to expand the containing divs.
#keyframes rotateClockwise {
0% {transform: rotate(0);}
100% {transform: rotate(90deg);}
}
#keyframes rotateAnticlockwise {
0% {transform: rotate(0);}
100% {transform: rotate(-90deg);}
}
.container {
width: 140px;
height: 86px;
position: relative;
}
.layer {
width: 50%;
height: 100%;
position: absolute;
overflow-x: hidden;
top: 0;
padding: 50% 0 50% 0;
margin: -50% 0 -50% 0;
}
.rotate {
width: 100%;
height: 50%;
background-color: black;
animation-duration: 5s;
}
.layer1 {
left: 0;
}
.layer2 {
left: 50%;
}
.rotate1 {
animation-name: rotateClockwise;
transform-origin: bottom right;
}
.rotate2 {
animation-name: rotateAnticlockwise;
transform-origin: top right;
}
.rotate3 {
animation-name: rotateAnticlockwise;
transform-origin: bottom left;
}
.rotate4 {
animation-name: rotateClockwise;
transform-origin: top left;
}
<div class="container">
<div class="layer layer1">
<div class="rotate rotate1"></div>
<div class="rotate rotate2"></div>
</div>
<div class="layer layer2">
<div class="rotate rotate3"></div>
<div class="rotate rotate4"></div>
</div>
</div>

CSS animation not behaving as expected

Problem
I've made a simple css animation, but it's not behaving as I expect it.
The idea is for the animation to draw a straight line (from top downwards) , and the disappear (also from the top downwards).
The start of the line moves down a bit, as the animation starts, then up again to stay at set position (same goes for the bottom at the end of the animation).
Question
How do I get the start of the line to stay at one position instead of 'bouncing' down and up?
Expected behavior
Actual behavior
Code
.lineWrapper {
width: 1px;
height: 300px;
margin: auto;
position: relative;
}
.lineWrapper .line {
width: 100%;
height: 100%;
background: #000;
animation: scrollLine 5s linear infinite;
}
#keyframes scrollLine {
0% {
transform: scaleY(0);
}
10% {
transform: scaleY(0);
transform-origin: top;
}
30% {
transform: scaleY(1);
}
70% {
transform: scaleY(1);
}
90% {
transform: scaleY(0);
transform-origin: bottom;
}
100% {
transform: scaleY(0);
}
}
<div class="lineWrapper">
<div class="line"></div>
</div>
Codepen
https://codepen.io/strazan/pen/RwPYgjq
The default transform-origin is center so if you omit it in the initial and last state it will be set to center. You need to also have an instant change of the transform-origin in the middle:
.lineWrapper {
width: 1px;
height: 300px;
margin: auto;
position: relative;
}
.line {
height: 100%;
background: #000;
animation: scrollLine 5s infinite;
}
#keyframes scrollLine {
0%,10% {
transform: scaleY(0);
transform-origin: top;
}
49.9% {
transform: scaleY(1);
transform-origin: top;
}
50% {
transform: scaleY(1);
transform-origin: bottom;
}
90%,100% {
transform: scaleY(0);
transform-origin: bottom;
}
}
<div class="lineWrapper">
<div class="line"></div>
</div>
I have made similar CSS animation with some different code lines.
body {
margin: 0px;
display: flex;
justify-content: center;
background: black;
overflow: hidden;
}
.line-wrapper {
height: 800px;
width: 8px;
background: tranparent;
display: flex;
justify-content: center;
animation: down 2s linear infinite;
}
#keyframes down {
0% {
transform: translateY(0px);
}
15% {
transform: translateY(0px);
}
30% {
transform: translateY(0px);
}
60% {
transform: translateY(90px);
}
90% {
transform: translateY(115px);
}
100% {
transform: translateY(115px);
}
}
.line {
height: 8px;
width: 4px;
background: Gray;
animation: scrollLine 2s ease-in-out infinite;
}
#keyframes scrollLine {
100% {
height: 800px;
}
}
.eraser {
height: 0px;
width: 4px;
background: black;
animation: rmv 2s linear infinite;
}
#keyframes rmv {
55% {
height: 0px;
}
100% {
height: 800px;
}
}
<div class="line-wrapper">
<div class="line">
<div class="eraser"></div>
</div>
</div>

Can a nested div ignore the hover of a parent

If a div is nested inside of another, can the nested div ignore the hover of the parent. Here's an example
.Box {
width: 50px;
height: 50px;
background: red;
}
.Circle {
width: 20px;
height: 20px;
background: blue;
border-radius: 20px;
}
.Box:hover {
animation: expand .5s normal forwards;
}
#keyframes expand {
0% {
transform: scale(1);
}
100% {
transform: scale(1.6);
}
}
<div class="Box">
<div class="Circle"></div>
</div>
In this example would there be a way to make the Box expand but not the Circle
Technically the parent hover event doesn't get applied to the child.
But in your case the child is still effected, because you're scaling the parent. And thus everything inside of the parent is being scaled too.
In order to counter the scaling of the nested div, you can apply a reverse scaling effect when the parent div is hovered.
.Box{
width: 50px;
height: 50px;
background: red;
}
.Circle{
width: 20px;
height: 20px;
background: blue;
border-radius: 20px;
}
.Box:hover{
animation: expand .5s normal forwards;
}
.Box:hover .Circle {
animation: contract .5s normal forwards;
}
#keyframes expand {
0% {
transform: scale(1);
}
100% {
transform: scale(1.6);
}
}
#keyframes contract {
0% {
transform: scale(1);
}
100% {
transform: scale(0.625); /* 1 / 1.6 */
}
}
<div class="Box">
<div class="Circle"></div>
</div>
Because you are scaling the parent, everything inside it will be impacted. An alternative solution is to have a different sibling to the circle and apply the animation on that.
CSS:
.Box {
width: 50px;
height: 50px;
background: red;
}
.Circle {
width: 20px;
height: 20px;
background: blue;
border-radius: 20px;
position: absolute;
top: 10px;
left: 10px;
}
.Container {
position: relative;
}
.Box:hover {
animation: expand .5s normal forwards;
}
#keyframes expand {
0% {
transform: scale(1);
}
100% {
transform: scale(1.6);
}
}
HTML:
<div class="Container">
<div class="Box">
</div>
<div class="Circle"></div>
</div>
Demo: http://jsfiddle.net/lotusgodkk/GCu2D/2157/
Here, the circle is positioned so that it's position is not affected by the box

How to use multiple keyframe animations in one?

I want to use two different keyframes animations, but when i name the second animation it does not seem to work. Basically i want to add the first animation to the first wrapper, and the second animation to the second wrapper at the same time, why this does not work?
#keyframes scroll {
0% {
-webkit-transform: translate(-30%, 0);
}
100% {
-webkit-transform: translate(-100%, 0);
}
}
#keyframes second {
0% {
-webkit-transform: translate(0, 0);
}
100% {
-webkit-transform: translate(-200%, 0);
}
}
.marquee {
display: block;
width: 100%;
white-space: nowrap;
overflow: hidden;
}
.wrapper {
background-color: lightblue;
display: inline-block;
padding-left: 100%;
animation: scroll 20s infinite linear;
}
.wrapper div {
background-color: whitesmoke;
display: inline-block;
margin-right: 10rem;
}
.wrapper div:last-child {
margin-right: 0px;
}
.wrapper2 {
background-color: lightblue;
display: inline-block;
padding-left: 100%;
animation: second 40s infinite linear;
}
.wrapper2 div {
background-color: whitesmoke;
display: inline-block;
margin-right: 10rem;
}
.wrapper2 div:last-child {
margin-right: 0px;
}
<div class="marquee">
<div class="wrapper">
<div>Akinfenwa</div>
<div>Dickenson</div>
<div>Watkins</div>
<div>Cowan-Hall</div>
</div>
<div class="wrapper2">
<div>Akinfenwa</div>
<div>Dickenson</div>
<div>Watkins</div>
<div>Cowan-Hall</div>
</div>
</div>
#keyframes scroll {
0% {
-webkit-transform: translate(-30%, 0);
}
100% {
-webkit-transform: translate(-100%, 0);
}
}
#keyframes second {
0% {
-webkit-transform: translate(0, 0);
}
100% {
-webkit-transform: translate(-200%, 0);
}
}
.marquee {
display: block;
width: 100%;
white-space: nowrap;
overflow: hidden;
}
.wrapper {
background-color: lightblue;
display: inline-block;
padding-left: 100%;
animation: scroll 10s infinite linear;
}
.wrapper div {
background-color: whitesmoke;
display: inline-block;
margin-right: 10rem;
}
.wrapper div:last-child {
margin-right: 0px;
}
.wrapper2 {
background-color: lightblue;
display: inline-block;
padding-left: 100%;
animation: second 20s infinite linear;
}
.wrapper2 div {
background-color: whitesmoke;
display: inline-block;
margin-right: 10rem;
}
.wrapper2 div:last-child {
margin-right: 0px;
}
<div class="marquee">
<div class="wrapper">
<div>Akinfenwa</div>
<div>Dickenson</div>
<div>Watkins</div>
<div>Cowan-Hall</div>
</div>
<div class="wrapper2">
<div>Akinfenwa2</div>
<div>Dickenson2</div>
<div>Watkins2</div>
<div>Cowan-Hall2</div>
</div>
</div>