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.
Related
I have some cards in a div and want them to change width on hover, but have two issues whith it:
I want to use transition , but the cards that are not hovered do transition after hovered card ends one. I want do it simultaneously.
How to change origin for 3rd and 4th card, so they change their width from right to left?
here is my code
body {
background-color: #333;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.cardBox {
width: 800px;
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 20px;
background-color: rgb(200, 201, 202);
padding: 20px;
overflow: hidden;
}
.card {
height: 450px;
background-color: #fff;
width: 100%
}
.card:hover {
width: 450px;
transition: all 1s ease;
}
.card:hover~ :not(:hover) {
width: 100%;
transition: all 1s ease;
}
.card img {
width: 100%;
height: 90%;
}
.card span {
text-transform: uppercase;
color: rgb(41, 40, 40);
font-weight: 600;
letter-spacing: 1.2px;
font-size: 20px;
display: block;
text-align: center;
line-height: 30px;
}
<div class="cardBox">
<div class="card">
<!-- <img src="/1.jpg" alt=""> -->
<span>CSS</span>
</div>
<div class="card">
<!-- <img src="/3.jpg" alt=""> -->
<span>image</span>
</div>
<div class="card">
<!-- <img src="/2.jpg" alt=""> -->
<span>hover</span>
</div>
<div class="card">
<!-- <img src="/4.jpg" alt=""> -->
<span>effect</span>
</div>
</div>
body {
background-color: #333;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.cardBox {
width: 800px;
display: flex;
gap: 20px;
background-color: rgb(200, 201, 202);
padding: 20px;
overflow: hidden;
}
.card {
height: 450px;
background-color: #fff;
width: 100%;
flex: 1;
}
.card:hover {
width: 450px;
transition: all 1s ease;
flex: 4;
}
.card:hover~ :not(:hover) {
width: 100%;
transition: all 1s ease;
}
.card img {
width: 100%;
height: 90%;
}
.card span {
text-transform: uppercase;
color: rgb(41, 40, 40);
font-weight: 600;
letter-spacing: 1.2px;
font-size: 20px;
display: block;
text-align: center;
line-height: 30px;
}
<div class="cardBox">
<div class="card">
<!-- <img src="/1.jpg" alt=""> -->
<span>CSS</span>
</div>
<div class="card">
<!-- <img src="/3.jpg" alt=""> -->
<span>image</span>
</div>
<div class="card">
<!-- <img src="/2.jpg" alt=""> -->
<span>hover</span>
</div>
<div class="card">
<!-- <img src="/4.jpg" alt=""> -->
<span>effect</span>
</div>
</div>
The problem was grid display and wrong css selector (.card:hover~ :not(:hover)). Also, use transition in the selector not in :hover selector.
body {
background-color: #333;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.cardBox {
width: 800px;
/* display: grid;
grid-template-columns: repeat(4, 1fr); */
display: flex;
gap: 20px;
background-color: rgb(200, 201, 202);
padding: 20px;
overflow: hidden;
}
.card {
height: 450px;
background-color: #fff;
/* width: 100% */
width: 25%;
transition: all 1s ease;
}
.card:hover {
width: 450px;
/* transition: all 1s ease; */
}
/* .card:hover~ :not(:hover) {
width: 100%;
transition: all 1s ease;
} */
.card img {
width: 100%;
height: 90%;
}
.card span {
text-transform: uppercase;
color: rgb(41, 40, 40);
font-weight: 600;
letter-spacing: 1.2px;
font-size: 20px;
display: block;
text-align: center;
line-height: 30px;
}
<div class="cardBox">
<div class="card">
<!-- <img src="/1.jpg" alt=""> -->
<span>CSS</span>
</div>
<div class="card">
<!-- <img src="/3.jpg" alt=""> -->
<span>image</span>
</div>
<div class="card">
<!-- <img src="/2.jpg" alt=""> -->
<span>hover</span>
</div>
<div class="card">
<!-- <img src="/4.jpg" alt=""> -->
<span>effect</span>
</div>
</div>
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;}
I'm trying to create a circle as an ::after pseudo element, which resizes automatically depending on its content.
.container {
display: flex;
flex-direction: row;
}
#dividerHost2 #left {
flex: 1 1 auto;
background-color: yellowgreen;
height: 200px;
}
#dividerHost2 #right {
flex: 1 1 auto;
background-color: dodgerblue;
}
#dividerHost2 .divider {
background-color: white;
margin: 0px;
width: 6px;
font-weight: 800;
}
.divider.vertical {
--divider-color: transparent;
display: inline-flex;
width: 1px;
border-left: 1px solid rgb(var(--divider-color));
margin: 0px 2px 0px 2px;
overflow: show;
}
.divider.vertical.title::after {
flex: 0 0 auto;
align-self: center;
border-radius: 50%;
content: "OR";
padding: 9px 8px 11px 8px;
background-color: white;
color: black;
transform: translateX(-44%);
z-index: 10;
}
<div id="dividerHost2" class="container">
<div id="left" class="container" style="flex-direction: row;"></div>
<div id="divider3" class="divider vertical title"></div>
<div id="right" class="container" style="flex-direction: row;"></div>
</div>
That gives a pretty nice result so far:
JSFiddle https://jsfiddle.net/jsnbtmh3/
However, with longer text the circle turns into an oval:
How to make the circle auto resize depending on its content?
Here is a trick using radial-gradient. The idea is to keep the element full height and color it using circle closest-side which will always create a circle that will start from the center and expand to the closest sides (left and right one)
I simplified the code to keep only the relevant part:
.container {
display: flex;
flex-direction: row;
margin:10px;
}
.left {
flex: 1 1 auto;
background-color: yellowgreen;
height: 200px;
}
.right {
flex: 1 1 auto;
background-color: dodgerblue;
}
.divider {
background-color: white;
width: 6px;
font-weight: 800;
display: flex;
justify-content: center;
}
.divider::after {
display: flex;
align-items: center;
flex: 0 0 auto;
content: attr(data-text);
padding: 0 8px;
background: radial-gradient(circle closest-side, white 98%, transparent 100%);
z-index: 10;
}
<div class="container">
<div class="left "></div>
<div class="divider" data-text="OR"></div>
<div class="right "></div>
</div>
<div class="container">
<div class="left "></div>
<div class="divider" data-text="longer"></div>
<div class="right "></div>
</div>
<div class="container">
<div class="left "></div>
<div class="divider" data-text="even longer"></div>
<div class="right "></div>
</div>
Don't put actual content in the pseudo-element especially as this is actually "content" rather than styling, rather use the pseudo-element to create a background circle using the padding/aspect ratio trick.
body {
text-align: center;
}
.divider {
margin: 3em;
display: inline-block;
position: relative;
padding: 1em;
font-weight: bold;
}
.divider:after {
content: "";
position: absolute;
width: 100%;
padding-top: 100%;
background: lightblue;
border-radius: 50%;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
z-index: -1;
}
<div class="divider">OR</div>
<div class="divider">LONG TEXT</div>
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>
I'm trying to show element B (share) when hovering element A (project-footer). Any ideas?
body {
margin: 0px;
}
.main-wrapper {
max-width: 400px;
height: 100%;
margin: 0px auto;
}
.project-wrapper {
display: flex;
flex-direction: column;
height: 320px;
margin-top: 100px;
}
.project-header {
display: flex;
flex-direction: row;
height: 40px;
width: 100%
}
.column {
display: flex;
flex-direction: column;
width: 50%;
}
.title {
width: 100px;
height: 18px;
border-radius: 3px;
background-color: #533C86;
}
.owner {
width: 85px;
height: 14px;
border-radius: 3px;
background-color: #533C86;
margin-top: 8px;
}
.more {
height: 40px;
width: 40px;
background-color: #F4F4F4;
margin-left: auto;
border-radius: 100px;
}
.project-body {
width: 400px;
height: 265px;
background-color: #47C7C3;
border-radius: 3px;
margin-top: 10px;
display: inherit;
}
.project-footer {
width: 400px;
height: 60px;
background-color: #31A8A4;
margin-top: auto;
border-bottom-left-radius: 3px;
border-bottom-right-radius: 3px;
display: inherit;
flex-direction: row;
transition: background-color 0.2s ease-out, padding 0.1s ease-out;
opacity: 1;
}
.project-footer:hover {
cursor: pointer;
background-color: #B5B5B5;
padding: 30px;
}
.share {
height: 40px;
width: 40px;
background-color: #F4F4F4;
margin-bottom: 10px;
margin-top: 10px;
border-radius: 100px;
margin-right: 10px;
margin-left: auto;
transition: width 0.1s ease-out, opacity 0.1s linear;
}
.share:hover {
width: 100px;
}
<body>
<div class="main-wrapper">
<div class="project-wrapper">
<div class="project-header">
<div class="column">
<div class="title"></div>
<div class="owner"></div>
</div>
<div class="column">
<div class="more icon"></div>
</div>
</div>
<div class="project-body">
<div class="badges">
<div class="badgde"></div>
<div class="badgde"></div>
</div>
<div class="project-footer">
<div class="column">
<div class="user"></div>
<div class="user"></div>
<div class="user"></div>
</div>
<div class="column">
<div class="share icon"></div>
</div>
</div>
</div>
</div>
</div>
</body>
http://jsfiddle.net/lombi/xx8n8dux/
try to add this jQuery, use mouseover and mouseout.
<script>
$(document).ready(function(e){
$(".project-footer").mouseover(function(){
$(".share").width(100);
});
$(".project-footer").mouseout(function(){
$(".share").width(40);
});
});
</script>
use the display property
.share{
display:none;
}
.project-footer:hover .share{
display:block;
}