I am trying to make a flip card work through a button, it is working normally with :hover but I cannot make it work with a button. I've tried using jquery and it didn't work can someone help me with this problem? (Im using bootstrap)
.card-flip > div {
backface-visibility: hidden;
transition: transform 300ms;
transition-timing-function: linear;
width: 100%;
height: 100%;
margin: 0;
display: flex;
}
.card-front {
transform: rotateY(0deg);
}
.card-back {
transform: rotateY(180deg);
position: absolute;
top: 0;
}
.card-flip:hover .card-front {
transform: rotateY(-180deg);
}
.card-flip:hover .card-back {
transform: rotateY(0deg);
}
.test{
background-color: green;
}
.test2{
background-color: yellow;
}
<div class="container">
<div class="card card-flip h-100 test">
<div class="card-front text-white bg-dark">
<div class="card-body">
<i class="fa fa-search fa-5x float-right"></i>
<h3 class="card-title">Front</h3>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
</div>
</div>
<div class="card-back bg-white test2">
<div class="card-body">
<h3 class="card-title">Back</h3>
<p class="card-text">Suprise this one has more more more more content on the back!</p>
Action
</div>
</div>
</div>
</div>
did you want it? if you wedge on the yellow block, you will go back.
$('.card-flip').on('click', function() {
$('.card-front').css('transform', 'rotateY(-180deg)');
$('.card-back').css('transform', 'rotateY(0deg)');
});
$(document).on('click', '.card-back', function() {
$(this).css('transform', '');
$('.card-front').css('transform', '');
});
.card-flip > div {
backface-visibility: hidden;
transition: transform 300ms;
transition-timing-function: linear;
width: 100%;
height: 100%;
margin: 0;
display: flex;
}
.card-front {
transform: rotateY(0deg);
}
.card-back {
transform: rotateY(180deg);
position: absolute;
top: 0;
}
/*.card-flip:hover .card-front {
transform: rotateY(-180deg);
}
.card-flip:hover .card-back {
transform: rotateY(0deg);
}*/
.test{
background-color: green;
}
.test2{
background-color: yellow;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
<div class="card card-flip h-100 test">
<div class="card-front text-white bg-dark">
<div class="card-body">
<i class="fa fa-search fa-5x float-right"></i>
<h3 class="card-title">Front</h3>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
</div>
</div>
<div class="card-back bg-white test2">
<div class="card-body">
<h3 class="card-title">Back</h3>
<p class="card-text">Suprise this one has more more more more content on the back!</p>
Action
</div>
</div>
</div>
</div>
Related
Am trying to achieve this animation on the CISO website header. I created a fiddle showing what i was able to achieve but something seems off.
img {
transition: all .3s ease;
overflow: hidden;
width: 100%;
margin: 0;
padding: 0;
height: auto;
}
#img2 {}
#img1,
#img3 {
z-index: 3;
}
/* hover effects */
#img2:hover {
transform: scaleX(1.08);
z-index: 8;
}
#img1:hover {
transform: scaleX(1.08);
z-index: 8;
}
#img3:hover {
transform: scaleX(1.08);
z-index: 8;
}
<div class="container">
<div class="d-flex bd-highlight">
<div class="flex-fill bd-highlight">
<img src="https://placeimg.com/640/480/animals" alt="" id="img1">
</div>
<div class="flex-fill bd-highlight">
<img src="https://placeimg.com/640/480/nature" alt="" id="img2">
</div>
<div class="flex-fill bd-highlight">
<img src="https://placeimg.com/640/480/arch" alt="" id="img3">
</div>
</div>
</div>
Am using bootstrap framework to align the images.
Just add this css
.flex-fill{
display:inline-block;
width:33%;
}
img:not(:hover) {
transition: none;
}
I need some help with a bootstrap flip card.
I try to create a Bootstrap flip card, but I cannot figure out how to get the back side on the same position as the front side. Can somebody help me please?
.card-flip>div {
backface-visibility: hidden;
transition: transform 300ms;
transition-timing-function: linear;
width: 100%;
height: 100%;
/* margin: 0; */
/* display: flex; */
}
.card-front {
transform: rotateY(0deg);
}
.card-back {
transform: rotateY(180deg);
position: relative;
top: 0;
}
.card-flip:hover .card-front {
transform: rotateY(-180deg);
}
.card-flip:hover .card-back {
transform: rotateY(0deg);
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet">
<!-- Material Design Bootstrap -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.11.0/css/mdb.min.css" rel="stylesheet">
<header>
<nav class="navbar navbar-expand-md">
<div class="navbar-brand">
<strong>Header</strong>
</div>
</nav>
</header>
<main style="min-height: calc(100vh - 111px); display: inline-block; width: 100%;">
<div class="card-flip h-100">
<div class="container my-5 z-depth-3 p-3 card-front">
<h3 class="text-center display-4 mb-4">Front</h3>
</div>
<div class="container my-5 z-depth-3 p-3 card-back">
<h3 class="text-center display-4 mb-4">Back</h3>
</div>
</div>
</main>
<footer class="page-footer text-center font-small black-text">
<div class="py-1">
Footer
</div>
</footer>
Change position: relative to position: absolute for card-back so it will stick on top of card-front.
.card-flip {
display: flex;
flex-direction: column;
align-items: center;
position: relative;
}
.card-flip>div {
backface-visibility: hidden;
transition: transform 300ms;
transition-timing-function: linear;
/* margin: 0; */
/* display: flex; */
}
.card-front {
transform: rotateY(0deg);
}
.card-back {
transform: rotateY(180deg);
position: absolute;
top: 0;
}
.card-flip:hover .card-front {
transform: rotateY(-180deg);
}
.card-flip:hover .card-back {
transform: rotateY(0deg);
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet">
<!-- Material Design Bootstrap -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.11.0/css/mdb.min.css" rel="stylesheet">
<header>
<nav class="navbar navbar-expand-md">
<div class="navbar-brand">
<strong>Header</strong>
</div>
</nav>
</header>
<main style="min-height: calc(100vh - 111px); display: inline-block; width: 100%;">
<div class="card-flip h-100">
<div class="container my-5 z-depth-3 p-3 card-front">
<h3 class="text-center display-4 mb-4">Front</h3>
</div>
<div class="container my-5 z-depth-3 p-3 card-back">
<h3 class="text-center display-4 mb-4">Back</h3>
</div>
</div>
</main>
<footer class="page-footer text-center font-small black-text">
<div class="py-1">
Footer
</div>
</footer>
Edit I've added flex-box properties to card-flip. So it'll set the position at the center.
I'm attempting to centre an image and div layer inside a containing div, but so far I can't get it to move from the left of the column. I've tried a few different ways but just can't get it to move. Even the margin auto trick isn't working, which I suspect is because bootstrap 4 is a flex box now.
HTML:
#user-avatar {
background: #ff4e00;
border-radius: 50%;
width: 250px;
margin-bottom: 25px;
position: relative;
}
#user img {
border-radius: 50%;
width: 250px;
transition: .5s ease;
backface-visibility: hidden;
}
#user-avatar:hover img {
cursor: pointer;
opacity: 0.3;
}
.middle {
transition: .5s ease;
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.middle i {
font-size: 34px;
}
#user-avatar:hover .middle {
opacity: 1;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet"/>
<div id="user" class="col-12">
<div class="col-12" id="user-avatar">
<img class="mx-auto d-block" src="assets/users/av-lg/liane.png" />
<div class="middle">
<i class="fas fa-camera-alt"></i>
<p>Edit Avatar</p>
</div>
</div>
<p id="username" class="text-center"><span>Howdy </span>Liane</p>
<div id="xp-bar" class="text-left">
<div id="xp"><p><i class="fas fa-stars"></i> XP</p></div>
</div>
<p id="stats" class="text-right">Level 1</p>
</div>
It's the image and the 'underlay' ('middle' div) that I need to be in the center.
Add margin-left: 50% and transform: translateX(-50%) to #user-avatar. check below link.
thank you
http://jsfiddle.net/x1hphsvb/10994/
Add Class on id="user-avatar" to mx-auto
<div class="col-12 mx-auto" id="user-avatar">
<img class="d-block" src="assets/users/av-lg/liane.png" />
<div class="middle">
<i class="fas fa-camera-alt"></i>
<p>Edit Avatar</p>
</div>
</div>
https://jsfiddle.net/lalji1051/v06j8orn/9/
simply add this style - centrd now
#user-avatar {
margin: 0 auto;
}
I am creating my own card using Bootstrap v4 (with only rows and columns). The problem is when I try to put the two sides of the card on top of each other. I use position: absolute; They disappear completely
.thecard {
perspective: 150rem;
-moz-perspective: 150rem;
position: relative;
}
.thecard__side {
background-color: orangered;
color: #fff;
font-size: 2rem;
height: 50rem;
transition: all .8s;
position: absolute;
top: 0;
left: 0;
width: 100%;
backface-visibility: hidden;
}
.thecard__side--front {
background-color: orangered;
}
.thecard__side--back {
background-color: green;
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.thecard:hover .thecard__side--front {
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.thecard:hover .thecard__side--back {
-webkit-transform: rotateY(0);
transform: rotateY(0);
}
<div class="row mt-5">
<div class="mt-5 mt-lg-0 col-md-6 col-lg-4">
<div class="thecard">
<div class="thecard__side thecard__side--front">
Front
</div>
<div class="thecard__side thecard__side--back">
Back
</div>
</div>
</div>
<div class="mt-5 mt-lg-0 col-md-6 col-lg-4">
<div class="thecard">
<div class="thecard__side thecard__side--front">
Front
</div>
<div class="thecard__side thecard__side--back">
Back
</div>
</div>
</div>
<div class=" offset-md-3 mt-5 mt-lg-0 offset-lg-0 col-md-6 col-lg-4">
<div class="thecard">
<div class="thecard__side thecard__side--front">
Front
</div>
<div class="thecard__side thecard__side--back">
Back
</div>
</div>
</div>
</div>
any solution guys?
After multiple testing, the same height on both these classes fixed the issue for me:
.thecard {
perspective: 150rem;
-moz-perspective: 150rem;
position: relative;
height: 50rem;
}
.thecard__side {
background-color: orangered;
color: #fff;
font-size: 2rem;
height: 50rem;
transition: all .8s;
position: absolute;
top: 0;
left: 0;
width: 100%;
backface-visibility: hidden;
}
You Can Try This Code
.thecard {
perspective: 150rem;
-moz-perspective: 150rem;
position: relative;
height: 350px;
}
.thecard__side {
background-color: orangered;
color: #fff;
font-size: 2rem;
height: 50rem;
transition: all .8s;
position: absolute;
top: 0;
left: 0;
width: 100%;
backface-visibility: hidden;
}
.thecard__side--front {
background-color: orangered;
}
.thecard__side--back {
background-color: green;
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.thecard:hover .thecard__side--front {
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.thecard:hover .thecard__side--back {
-webkit-transform: rotateY(0);
transform: rotateY(0);
}
<div class="row mt-5">
<div class="mt-5 mt-lg-0 col-md-6 col-lg-4">
<div class="thecard">
<div class="thecard__side thecard__side--front">
Front
</div>
<div class="thecard__side thecard__side--back">
Back
</div>
</div>
</div>
<div class="mt-5 mt-lg-0 col-md-6 col-lg-4">
<div class="thecard">
<div class="thecard__side thecard__side--front">
Front
</div>
<div class="thecard__side thecard__side--back">
Back
</div>
</div>
</div>
<div class=" offset-md-3 mt-5 mt-lg-0 offset-lg-0 col-md-6 col-lg-4">
<div class="thecard">
<div class="thecard__side thecard__side--front">
Front
</div>
<div class="thecard__side thecard__side--back">
Back
</div>
</div>
</div>
</div>
I have 3 boxes within a fluid container.
Each box has a heading title, an icon and some text below.
On :hover I want the icon to move to the top of the <div> and change it's size, I have managed to "achieve" it but using certain number of pixels.
That will not work in mobile resolutions if the title text is longer and takes 2 lines.
Here is what I have done so far:
Fiddle here
HTML
<div class="container">
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 text-center market-blocks orange wow rollIn">
<div class="service-box">
<h2>Title</h2>
<i class="fa fa-5x fa-paper-plane wow bounceIn market-icon" data-wow-delay=".1s"></i>
<p class="">Certain text below the icon</p>
</div>
</div>
</div>
CSS
.container{
text-align:center;
}
.market-blocks{
background: #3aa0d1;
padding: 30px 0 30px 0;
cursor:pointer;
}
.orange{
background: #e97d68;
}
i.market-icon {
-webkit-transition: 1s ease-in;
-moz-transition: 1s ease-in;
-o-transition: 1s ease-in;
transition: 1s ease-in
}
.market-blocks:hover i.market-icon {
-webkit-transform: translate(0,-70px);
-moz-transform: translate(0,-70px);
-o-transform: translate(0,-70px);
-ms-transform: translate(0,-70px);
transform: translate(0,-70px);
font-size: 1.8em;
}
How can I do it? And also is there a better way to do the movement from the initial position to the top of the <div>?
Pure HTML/CSS solution:
.container {
text-align: center;
}
.market-blocks {
background: #3aa0d1;
padding: 30px 0;
cursor: pointer;
}
.orange {
background: #e97d68;
}
.service-box {
display: inline-block;
}
.service-box-header {
position: relative;
}
.market-title {
padding-bottom: 5em;
-webkit-transition: 1s ease-in;
transition: 1s ease-in
}
.market-icon {
position: absolute;
right: 0;
bottom: 0;
left: 0;
-webkit-transition: 1s ease-in;
transition: 1s ease-in
}
.market-blocks:hover .market-title {
padding-bottom: 0;
}
.market-blocks:hover .market-icon {
bottom: 100%;
font-size: 1.8em;
}
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 text-center market-blocks orange wow rollIn">
<div class="service-box">
<div class="service-box-header">
<h2 class="market-title">Very-very-very-very-very-very-very-very loooooooooooooooooooong title</h2>
<i class="fa fa-5x fa-paper-plane wow bounceIn market-icon"></i>
</div>
<p class="">Certain text below the icon</p>
</div>
</div>
</div>
</div>