I am able to achieve smooth in and out effect using transform and transition. I was experimenting with animation but could not achieve smooth out effect.
The first example below works. Note that when you hover, the card will move. And when you no longer hover, the cards to the right will close in slowly.
The second example is the one I'm trying to improve. How can you make the cards close in slowly when using animation? Thanks in advance.
EXAMPLE 1
.container {
display: flex;
margin-top: 100px;
justify-content: center;
}
.card {
height: 200px;
width: 200px;
background-color: antiquewhite;
border: 1px solid black;
border-radius: 15px;
box-shadow: 1px 1px 15px 1px;
display: flex;
justify-content: center;
align-items: center;
transition: 1s;
}
.card:not(:first-child) {
margin-left: -150px;
}
.card:hover {
transform: translateY(-20px);
}
.card:not(:last-child):hover ~ .card {
transform: translateX(170px);
}
<div class="container">
<div class="card">
CARD
</div>
<div class="card">
CARD
</div>
<div class="card">
CARD
</div>
<div class="card">
CARD
</div>
<div class="card">
CARD
</div>
</div>
EXAMPLE 2
.container2 {
display: flex;
justify-content: center;
margin-top: 200px;
}
.tile {
height: 200px;
width: 200px;
background-color: antiquewhite;
border: 1px solid black;
border-radius: 15px;
box-shadow: 1px 1px 15px 1px;
display: flex;
justify-content: center;
align-items: center;
}
.tile:not(:first-child) {
margin-left: -150px;
}
.tile:not(:last-child):hover ~ .tile {
animation: slide 0.8s linear forwards;
}
#keyframes slide {
0% {
transform: translateX(0px);
}
100% {
transform: translateX(170px);
}
}
.tile:hover {
animation: float 0.8s forwards;
}
#keyframes float {
0% {
transform: translateY(0px);
}
100% {
transform: translateY(-15px);
}
}
<div class="container container2">
<div class="tile">
CARD
</div>
<div class="tile">
CARD
</div>
<div class="tile">
CARD
</div>
<div class="tile">
CARD
</div>
<div class="tile">
CARD
</div>
</div>
hi in the tile class you should add an animation like this:
.tile {
height: 200px;
width: 200px;
background-color: antiquewhite;
border: 1px solid black;
border-radius: 15px;
box-shadow: 1px 1px 15px 1px;
display: flex;
justify-content: center;
align-items: center;
animation-duration: 0.8s;}
Related
I am using the Bootstrap 4 in React. Currently, the card for Item 1 is shorter than Item 2, but I want both the cards to have the same height.
I am expected to have more cards added to the bottom in the future.
My CSS file:
.CountryDetail {
width: 70%;
display: flex;
flex-wrap: wrap;
justify-content: center;
margin-left: 15%;
margin-right: 15%;
}
.cards {
background: #fcfcfc;
margin: 20px 40px;
transition: 0.4s all;
width: 800px;
padding: 20px;
margin-left: auto;
margin-right: auto;
}
.icon-size {
font-size: 50px;
}
.shadow-1 {
position: relative;
left: 0;
right: 0;
top: 0;
bottom: 0;
z-index: 0;
box-sizing: border-box;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.13);
}
.shadow-1:hover {
z-index: 1;
box-shadow: 0 8px 50px rgba(0, 0, 0, 0.2);
transform: scale(1.05);
transition: all 0.5s ease;
}
.vertical-center {
justify-content: center;
}
.show-hover {
opacity: 0;
transform: translateX(-20px);
transition: 1s all;
}
.cards:hover .show-hover {
opacity: 1;
transform: translateX(0px);
color: blue;
}
.vertical-align {
display: flex;
align-items: center;
}
My JavaScript file:
<div className="CountryDetail">
<div className="cards shadow-1 container">
<div className="row vertical-align">
<div className="col-2 text-center">
<FontAwesomeIcon className="icon-hover icon-size" icon={faPlane} color="#A9A9A9" />
</div>
<div className="col-8">
<h3>Item 1</h3>
</div>
<div className="col-2 text-center">
<FontAwesomeIcon className="show-hover icon-size" icon={faArrowRight} color="#A9A9A9" />
</div>
</div>
</div>
<div className="cards shadow-1 container">
<div className="row vertical-align">
<div className="col-2 text-center">
<FontAwesomeIcon className="icon-hover icon-size" icon={faHeart} color="#A9A9A9" />
</div>
<div className="col-8">
<h3>Item 2</h3>
<span>Under Construction...</span>
<h2>Testing</h2>
</div>
<div className="col-2 text-center">
<FontAwesomeIcon className="show-hover icon-size" icon={faArrowRight} color="#A9A9A9" />
</div>
</div>
</div>
</div>
I have tried to add line-height or height in CSS for cards class, but it would mess up the height of the contents inside the card.
If I modify my "cards" class like this by adding min-height:
.cards {
min-height: 200px;
background: #fcfcfc;
margin: 20px 40px;
transition: 0.4s all;
width: 800px;
padding: 20px;
margin-left: auto;
margin-right: auto;
}
I would get this:
Based on your need of the same height and centered content, update your CSS to:
.cards {
display: flex;
flex-direction: column;
justify-content: center;
min-height: 200px;
background: #fcfcfc;
margin: 20px 40px;
transition: 0.4s all;
width: 800px;
padding: 20px;
margin-left: auto;
margin-right: auto;
}
If you set the card to be display flex, since you have only one direct child (row), you can center that vertically.
I'm using flex to display as set of divs and animating the images by setting their width to 95% on hover. This is my CSS:
.container {
display: flex;
flex-wrap: wrap;
align-content: center;
}
.box {
display: flex;
flex-direction: column;
justify-content: center;
margin-top: 1.5%;
align-items: center;
flex: 0 1 48%;
}
.img-container img {
width: 100%;
transition: width ease-in 0.15s;
}
.img-container:hover img {
width: 95%;
transition: width ease-in 0.15s;
}
My problem is that, because of the animation duration, if I hover on images from the top row, for a brief moment both animations are active, forcing the row's height to decrease, which makes the elements beneath it bounce up and down.
Is there a way to force the row to keep its height constant during these animations?
.container {
display: flex;
flex-wrap: wrap;
align-content: center;
}
.box {
display: flex;
flex-direction: column;
justify-content: center;
margin-top: 1.5%;
align-items: center;
margin-right: 2%;
flex: 0 1 48%;
}
.box:nth-of-type(2n) {
margin-right: 0;
}
.img-container {
text-align: center;
position: relative;
animation: fadein 1s;
animation-timing-function: ease-out;
}
.img-container img {
width: 100%;
transition: width ease-in 0.15s;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
.img-container:hover img {
width: 95%;
transition: width ease-in 0.15s;
}
<div class="container">
<div class="box">
<div class="img-container">
<img src="http://via.placeholder.com/800x800?text=1">
</div>
</div>
<div class="box">
<div class="img-container">
<img src="http://via.placeholder.com/800x800?text=2">
</div>
</div>
<div class="box">
<div class="img-container">
<img src="http://via.placeholder.com/800x800?text=3">
</div>
</div>
<div class="box">
<div class="img-container">
<img src="http://via.placeholder.com/800x800?text=4">
</div>
</div>
</div>
Example in this plunker.
You animate with transform: scale() instead. It will give you a much smoother animation and the other elements won't be affected.
.img-container img {
width: 100%;
transition: transform ease-in 0.15s;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
.img-container:hover img {
transform: scale(.95);
}
Stack snippet
.container {
display: flex;
flex-wrap: wrap;
align-content: center;
}
.box {
display: flex;
flex-direction: column;
justify-content: center;
margin-top: 1.5%;
align-items: center;
margin-right: 2%;
flex: 0 1 48%;
}
.box:nth-of-type(2n) {
margin-right: 0;
}
.img-container {
text-align: center;
position: relative;
animation: fadein 1s;
animation-timing-function: ease-out;
}
.img-container img {
width: 100%;
transition: transform ease-in 0.15s;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
.img-container:hover img {
transform: scale(.95);
}
<div class="container">
<div class="box">
<div class="img-container">
<img src="http://via.placeholder.com/800x800?text=1">
</div>
</div>
<div class="box">
<div class="img-container">
<img src="http://via.placeholder.com/800x800?text=2">
</div>
</div>
<div class="box">
<div class="img-container">
<img src="http://via.placeholder.com/800x800?text=3">
</div>
</div>
<div class="box">
<div class="img-container">
<img src="http://via.placeholder.com/800x800?text=4">
</div>
</div>
</div>
How can I modify the styles below to result in the elements having the same spacing between each after the scaling? (without absolutely positioning them)
Desired Result:
.menu-next, .menu-previous1 {
transform: scale(.9); transform-origin: left;
}
.menu-previous2 { transform: scale(.7); transform-origin: left;}
.menu-previous3 { transform: scale(.55); transform-origin: left;}
.menu {
background-color: gray;
padding: 10px;
}
.menu div {
display: block;
width: 20%;
padding: 10px;
background-color: white;
color: green;
}
<div class="menu">
<div class="menu-previous3">Items</div>
<div class="menu-previous2">Store</div>
<div class="menu-previous1">Friends</div>
<div class="menu-current" >Settings</div>
<div class="menu-next" >Other</div>
</div>
Use scale(x, y) and not scale(value) + transform-origin
.menu-next,
.menu-previous1 {
transform: scale(.9, 1);
transform-origin: left;
}
.menu-previous2 {
transform: scale(.7, 1);
transform-origin: left;
}
.menu-previous3 {
transform: scale(.55, 1);
transform-origin: left;
}
.menu {
display: flex;
flex-direction: column;
justify-content: center;
background-color: gray;
padding: 10px;
}
.menu div {
display: block;
width: 20%;
padding: 10px;
background-color: white;
border: 1px solid green;
color: green;
}
<div class="menu">
<div class="menu-previous3">Items</div>
<div class="menu-previous2">Store</div>
<div class="menu-previous1">Friends</div>
<div class="menu-current">Settings</div>
<div class="menu-next">Other</div>
</div>
With thatthere is an other problem : scalling text. But you can fix that with pseudo-element (like here)
The best way is to wrap the scaling items and apply the other ui properties seperately of items to that wrapping div and then apply the scaling to the item inside it only.
Here is your code with this theory applied and a little change of padding and margin for equal spacing:
.itemwrapper .menu-next, .itemwrapper .menu-previous1 {
transform: scale(.9); transform-origin: left;
}
.itemwrapper .menu-previous2 { transform: scale(.7); transform-origin: left;}
.itemwrapper .menu-previous3 { transform: scale(.55); transform-origin: left;}
.menu {
background-color: gray;
padding: 10px;
}
.itemwrapper{
display: block;
width: 20%;
padding: 5px 10px;
margin:2px;
background-color: white;
color: green;
}
<div class="menu">
<div class="itemwrapper"><div class="menu-previous3">Items</div></div>
<div class="itemwrapper"><div class="menu-previous2">Store</div></div>
<div class="itemwrapper"><div class="menu-previous1">Friends</div></div>
<div class="itemwrapper"><div class="menu-current" >Settings</div></div>
<div class="itemwrapper"><div class="menu-next" >Other</div></div>
</div>
Hope this helps.
May be you can adjust it by hand ... Not really a good solution, but it is difficult to go any better.
.menu-next,
.menu-previous1 {
transform: scale(.9);
}
.menu-previous2 {
transform: scale(.7);
margin-bottom: -6px;
}
.menu-previous3 {
transform: scale(.55);
margin-bottom: -12px;
}
.menu {
background-color: gray;
padding: 10px;
}
.menu div {
display: block;
width: 20%;
padding: 10px;
background-color: white;
color: green;
transform-origin: left;
}
<div class="menu">
<div class="menu-previous3">Items</div>
<div class="menu-previous2">Store</div>
<div class="menu-previous1">Friends</div>
<div class="menu-current">Settings</div>
<div class="menu-next">Other</div>
</div>
Based a bit off this answer and sort of hack-y: https://stackoverflow.com/a/16388428/1204415
Wrap your scaled divs, resize the wrappers, and move the scaled divs with negative margins within the wrappers. scale() seems to also scale borders, margins, and padding.
HTML
<div class="menu">
<div class="wrap1">
<div class="item menu-previous3">Items</div>
</div>
<div class="wrap2">
<div class="item menu-previous2">Store</div>
</div>
<div class="item menu-previous1">Friends</div>
<div class="item menu-current" >Settings</div>
<div class="item menu-next" >Other</div>
</div>
CSS
.wrap1 {
height: 20px;
margin: 0;
overflow: hidden;
background-color: black;
}
.wrap2 {
height: 32px;
margin: -5px 0 0 0;
overflow: hidden;
background-color: blue;
}
.menu-next, .menu-previous1 {
transform: scale(.9); transform-origin: left;
}
.menu-previous2 { transform: scale(.7); transform-origin: left;}
.menu-previous3 { transform: scale(.55); transform-origin: left; margin: -8px 0 0 0; }
.menu {
background-color: gray;
padding: 10px;
}
.menu .item {
display: block;
outline:1px solid red;
width: 20%;
padding: 10px;
background-color: white;
color: green;
}
A pen: https://codepen.io/dmoz/pen/vmjybo
I am making images with text on flipping cards. I am trying to put them on the site so there would be about nine of them, each time three of them next to one another. Here is my code. Please just simply directly tell me how to implement it as I did not manage to fix the issue myself beforehand. I have no exp with HTML or CSS and just need a quick fix for the site. Thanks!
So the HTML bit in the end will be reproduced about nine times, the implementation has to be efficient for each copy.
<style> #f1_container {
position: margin-left;
margin: 10px;
width: 150%;
height: 150%;
z-index: 1;
}
#f1_container {
perspective: 1000;
}
#f1_card {
width: 113px;
height: 170px;
transform-style: preserve-3d;
transition: all 1.0s linear;
}
#f1_container:hover #f1_card {
transform: rotateY(180deg);
box-shadow: -5px 5px 5px #aaa;
}
.face {
position: absolute;
width: 150%;
height: 150%;
backface-visibility: hidden;
}
.face.back {
display: block;
transform: rotateY(180deg);
box-sizing: border-box;
padding: 10px;
color: white;
text-align: center;
background-color: #aaa;
}
</style>
<div id="f1_container">
<div id="f1_card" class="shadow">
<div class="front face">
<img src="http://img11.hostingpics.net/pics/714153square1.png"/>
</div>
<div class="back face center">
<p>TContent</p>
<p>Content</p>
</div>
.cardCont {
display: inline-block;
padding: 20px;
}
/*sets transition speed for the card flip you can change this*/
.Card {
height: 150px;
width: 150px;
border: 1px solid black;
transition: all .4s;
}
/*rotates on hover of outer div*/
.cardCont:hover .Card {
transform: rotateY(-180deg);
}
/*sets transitions for the front and back.. delay should half the transition this way this will only show when the card is half flipped*/
.Card .front,
.Card .back {
transition: all .1s;
transition-delay: .2s;
}
/*fixes the fact that this will now be backwards and hides it normally*/
.Card .back {
transform: rotateY(180deg);
display: none;
width: 100%;
}
/*following 2 set default properties for the front and back.*/
.cardCont:hover .Card .front {
display: none;
}
.cardCont:hover .Card .back {
display: inline-block;
}
<div class="cardCont">
<div class="Card">
<div class="front">Card1 Front
<br />you can put what you want in here.. this is the front</div>
<div class="back">Card1 Back
<br />you can put what you want in here.. this is the back</div>
</div>
</div>
<div class="cardCont">
<div class="Card">
<div class="front">Card2 Front
<br />you can put what you want in here.. this is the front</div>
<div class="back">Card2 Back
<br />you can put what you want in here.. this is the back</div>
</div>
</div>
I got a problem with flexbox containers with absolute positioned childrens.
FIDDLE; if the window getting smaller (in width) the titles getting smaller, what is absolutly correct, the problem is in the digits that are overlapping over the other watches. I tested a bit around with z-Index, background-color but doesn't get anything work.
HTML:
<div class="stopwatch">
<div class="stopwatch__panel">
<div class="stopwatch__header">
<div class="stopwatch__title">Random Title 404531</div>
</div>
<div class="stopwatch__body">
<div class="stopwatch__counter">
<div class="stopwatch__segment stopwatch__segment--five">
<div class="stopwatch__segmentTopLeft"></div>
<div class="stopwatch__segmentTop"></div>
<div class="stopwatch__segmentTopRight"></div>
<div class="stopwatch__segmentMiddle">
<div class="stopwatch__segmentMiddleTop"></div>
<div class="stopwatch__segmentMiddleBottom"></div>
</div>
<div class="stopwatch__segmentBottomLeft"></div>
<div class="stopwatch__segmentBottom"></div>
<div class="stopwatch__segmentBottomRight"></div>
</div>
<div class="stopwatch__segment stopwatch__segment--five">
<div class="stopwatch__segmentTopLeft"></div>
<div class="stopwatch__segmentTop"></div>
<div class="stopwatch__segmentTopRight"></div>
<div class="stopwatch__segmentMiddle">
<div class="stopwatch__segmentMiddleTop"></div>
<div class="stopwatch__segmentMiddleBottom"></div>
</div>
<div class="stopwatch__segmentBottomLeft"></div>
<div class="stopwatch__segmentBottom"></div>
<div class="stopwatch__segmentBottomRight"></div>
</div>
</div>
</div>
</div>
<div class="stopwatch__panel">
<div class="stopwatch__header">
<div class="stopwatch__title">Random Title 714895</div>
</div>
<div class="stopwatch__body">
<div class="stopwatch__counter">
<div class="stopwatch__segment stopwatch__segment--nine">
<div class="stopwatch__segmentTopLeft"></div>
<div class="stopwatch__segmentTop"></div>
<div class="stopwatch__segmentTopRight"></div>
<div class="stopwatch__segmentMiddle">
<div class="stopwatch__segmentMiddleTop"></div>
<div class="stopwatch__segmentMiddleBottom"></div>
</div>
<div class="stopwatch__segmentBottomLeft"></div>
<div class="stopwatch__segmentBottom"></div>
<div class="stopwatch__segmentBottomRight"></div>
</div>
</div>
</div>
</div>
</div>
CSS:
.stopwatch {
position: fixed;
right: 0;
bottom: 0;
display: flex;
justify-content: flex-end;
align-items: flex-end;
max-width: 100%;
width: 100%;
}
.stopwatch__panel {
background-color: #ffffff;
border: 1px solid #dddddd;
display: flex;
flex-flow: column;
min-width: 0;
}
.stopwatch__header {
background-color: #f5f5f5;
display: flex;
align-items: center;
order: 1;
}
.stopwatch__title {
flex: 1 1 auto;
padding: 5px;
border-left: 1px solid #dddddd;
word-wrap: break-word;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.stopwatch__body {
display: flex;
align-items: stretch;
}
.stopwatch__counter {
background-color: #333333;
padding: 15px;
flex-grow: 1;
text-align: center;
color: #ffffff;
display: flex;
align-items: center;
justify-content: center;
}
.stopwatch__segment {
position: relative;
float: left;
margin: 6px;
width: 18px;
height: 35px;
transition: all 200ms ease-in-out;
}
.stopwatch__segment--zero .stopwatch__segmentTopRight {
border-right-color: #e6e6e6;
}
/* [...all numbers from zero to nine... (only coloring borders) ] */
.stopwatch__segment--nine .stopwatch__segmentBottom {
border-bottom-color: #e6e6e6;
}
.stopwatch__segmentTop {
position: absolute;
left: 1px;
height: 0;
width: 10px;
border-top: 3px solid #424242;
border-left: 3px solid transparent;
border-right: 3px solid transparent;
transition: all 200ms ease-in-out;
}
.stopwatch__segmentTopRight {
position: absolute;
left: 15px;
top: 1px;
height: 10px;
width: 0;
border-right: 3px solid #424242;
border-top: 3px solid transparent;
border-bottom: 3px solid transparent;
transition: all 200ms ease-in-out;
}
/* [... the other segments parts ...] */
add overflow:hidden; to .stopwatch__counter
.stopwatch__counter {
background-color: #333333;
padding: 15px;
flex-grow: 1;
text-align: center;
color: #ffffff;
display: flex;
overflow:hidden;
align-items: center;
justify-content: center; }
see this fiddle:
https://jsfiddle.net/grassog/jcgyce3g/2/