CSS3 transform rotate with transition - css

I've created a plus sign (+) with CSS using the :after pseudo element. When the containing element is clicked, I'm rotating (with a transform) the plus sign (+) 45 degrees to make an (x). When the containing element is clicked again, the (x) returns back to (+).
This works as expected, but it appears the position of the horizontal line that makes the (+) moves slightly down and the width gets smaller after the transform has completed.
It looks like this is only happening in Firefox.
I've created a fiddle to show what I mean.
Here is the code for reference:
$('#MobileProx').click(function() {
$('#MobileProx .RotateXWrap').toggleClass('Active');
return false;
});
#MobileProx {
position: relative;
top: 50px;
height: 20px;
display: block;
text-align: left;
padding: 2%;
color: #fff;
font-size: 1.5em;
background: #0099a8;
cursor: pointer;
}
#MobileProx .RotateXWrap {
transition: all 0.35s ease-in-out 0s;
-moz-transition: all .35s ease-in-out 0s;
-ms-transition: all .35s ease-in-out 0s;
-o-transition: all .35s ease-in-out 0s;
-webkit-transition: all .35s ease-in-out 0s;
}
#MobileProx .RotateXWrap {
float: right;
margin-right: 1%;
width: 20px;
height: 20px;
}
#MobileProx .RotateXWrap.Active {
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
#MobileProx .RotateX {
margin-left: 9px;
background: white;
border-radius: 10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
height: 20px;
position: absolute;
width: 3px;
}
#MobileProx .RotateX:after {
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
background: white;
content: "";
height: 3px;
left: -9px;
position: absolute;
top: 8.5px;
width: 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="MobileProx">Click here
<div class="RotateXWrap">
<span class="RotateX"></span>
</div>
</div>
Any suggestions?

Related

CSS perspective on pseudo elements blocks content lower half on IOS

So i made a simple button with a perspective pseudo element that flips on hover.
This works perfectly well on android and pc, but on iphone/ipad the text is only visible in the upper half.
Also tried adding a span for the text and position it above the stack, same result.
Does anyone know how to fix this?
Couldn't find a similar question on stack so far, but should be fixable i reckon.......
PS: i use scss, so it converts including -webkit and other variants..
This is how it looks on appetize.io (and real iphone):
.btn {
position: relative;
display: inline-block;
cursor: pointer;
padding: 12px 20px;
margin: 10px 10px;
text-decoration: none;
-webkit-perspective: 500px;
perspective: 500px;
color: #fff;
-webkit-transition: all .4s ease-in;
transition: all .4s ease-in;
z-index: 10;
line-height: 20px;
overflow: visible;
}
.btn:after {
content: '';
position: absolute;
width: 100%;
height: 100%;
background-color: #f00;
border-radius: 12px;
left: 0;
-webkit-perspective: 500px;
perspective: 500px;
-webkit-transform: translateY(-50%) rotateX(45deg);
transform: translateY(-50%) rotateX(45deg);
min-height: 20px;
top: 50%;
z-index: -10;
-webkit-transition: all .4s ease-out;
transition: all .4s ease-out
}
.btn:hover:after {
color: #fff;
-webkit-transform: translateY(-50%) rotateX(-135deg);
transform: translateY(-50%) rotateX(-135deg);
background-color: #000
}
<div class="btn">this is unreadable on ios?</div>

Change check box background color

Good afternoon.
I'm having a problem changing the background color of the checkboxes that are selected.
CheckBox to change
I've seen options on the internet and some questions right here in the stack. But none of them were successful. Below is the DOM image where the elements are inserted.
Dom about element
The last code I tested was this and it still didn't work
input[type=checkbox]:checked:after{
background-color: red !important;
color: blue !important;
}
Aimed to have a background in this color # FFEA00 when checked and the arrow to be # 000 when checked.
Best regards and thanks for the help
Yellow background when checked, black arrow when checked. It's here:
.checkbox-label {
display: block;
position: relative;
margin: auto;
cursor: pointer;
font-size: 22px;
line-height: 24px;
height: 24px;
width: 24px;
clear: both;
}
.checkbox-label input {
position: absolute;
opacity: 0;
cursor: pointer;
}
.checkbox-label .checkbox-custom {
position: absolute;
top: 0px;
left: 0px;
height: 24px;
width: 24px;
background-color: transparent;
border-radius: 5px;
transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-ms-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
border: 2px solid #000;
}
.checkbox-label input:checked ~ .checkbox-custom {
background-color: #FFEA00;
border-radius: 5px;
-webkit-transform: rotate(0deg) scale(1);
-ms-transform: rotate(0deg) scale(1);
transform: rotate(0deg) scale(1);
opacity:1;
border: 2px solid #000;
}
.checkbox-label .checkbox-custom::after {
position: absolute;
content: "";
left: 12px;
top: 12px;
height: 0px;
width: 0px;
border-radius: 5px;
border: solid #000;
border-width: 0 3px 3px 0;
-webkit-transform: rotate(0deg) scale(0);
-ms-transform: rotate(0deg) scale(0);
transform: rotate(0deg) scale(0);
opacity:1;
transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-ms-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
}
.checkbox-label input:checked ~ .checkbox-custom::after {
-webkit-transform: rotate(45deg) scale(1);
-ms-transform: rotate(45deg) scale(1);
transform: rotate(45deg) scale(1);
opacity:1;
left: 8px;
top: 3px;
width: 6px;
height: 12px;
border: solid #000000;
border-width: 0 2px 2px 0;
background-color: transparent;
border-radius: 0;
}
<div class="checkbox-container">
<label class="checkbox-label">
<input type="checkbox">
<span class="checkbox-custom"></span>
</label>
</div>

How to reverse a sequence of CSS transitions and transforms which contain span:nth-child

This CSS "animation" in essence consist of several transitions and transforms on span:nth-children which follow each other sequentially using transition delays. It works fine one way, but what is the best way to reverse the animation? Since it is a sequence the solution should reverse the entire sequence. See fiddle for example:
http://jsfiddle.net/musicformellons/6nb0wy68/
#Pqb-icon {
background: white;
width: 170px;
height: 100px;
border-radius: 5px;
position: relative;
overflow: hidden;
border: 2px solid salmon;
border-bottom: 20;
-webkit-transition: .9s ease-in-out;
-moz-transition: .9s ease-in-out;
-o-transition: .9s ease-in-out;
transition: .9s ease-in-out;
}
#Pqb-icon span {
display: block;
position: absolute;
border: 5px solid black;
width: 20px;
height: 20px;
bottom: 50px;
left: 12%;
background: rgba(255, 200, 220, 0.4);
transition-timing-function: ease;
}
#Pqb-icon span:nth-child(1) {
left: 12%;
border-radius: 25px;
-webkit-transform-origin: left center;
-moz-transform-origin: left center;
-o-transform-origin: left center;
transform-origin: left center;
}
#Pqb-icon.open span:nth-child(1) {
left: 12%;
border-radius: 25px;
-webkit-transition: .25s ease-in-out;
-moz-transition: .25s ease-in-out;
-o-transition: .25s ease-in-out;
transition: .25s ease-in-out;
}
#Pqb-icon.open span:nth-child(3) {
left: 36%;
bottom: 50px;
border-radius: 25px;
-webkit-transform: translate(-40px,0px);
-moz-transform: translate(-40px,0px);
-o-transform: translate(-40px,0px);
transform: translate(-40px,0px);
-webkit-transition: .25s ease .7s;
-moz-transition: .25s ease .7s;
-o-transition: .25s ease .7s;
transition: .4s ease .9s;
opacity: 0;
}
#Pqb-icon span:nth-child(2) {
width: 5px;
height: 38%;
bottom: 27%;
background: black;
border: 0px solid black;
-webkit-transform-origin: left center;
-moz-transform-origin: left center;
-o-transform-origin: left center;
transform-origin: left center;
}
#Pqb-icon.open span:nth-child(2) {
width: 5px;
height: 38%;
bottom: 27%;
background: black;
border: 0px solid black;
-webkit-transition: .25s ease-in-out;
-moz-transition: .25s ease-in-out;
-o-transition: .25s ease-in-out;
transition: .25s ease;
}
#Pqb-icon.open span:nth-child(4) {
width: 5px;
height: 38%;
bottom: 27%;
left: 15%;
background: black;
border: 0px solid black;
-webkit-transform: rotateZ(-180deg);
-moz-transform: rotateZ(-180deg);
-o-transform: rotateZ(-180deg);
transform: rotate(-180deg) ;
-webkit-transition: .25s ease-in-out .7s;
-moz-transition: .25s ease-in-out .7s;
-o-transition: .25s ease-in-out .65s;
transition: .4s ease .8s;
opacity: 0;
}
#Pqb-icon span:nth-child(3) {
bottom: 27%;
left: 28.5%;
border-radius: 25px;
-webkit-transform-origin: left center;
-moz-transform-origin: left center;
-o-transform-origin: left center;
transform-origin: left center;
}
#Pqb-icon.open span:nth-child(5) {
bottom: 27%;
left: 46%;
border-radius: 25px;
-webkit-transform: rotateZ(-180deg);
-moz-transform: rotateZ(-180deg);
-o-transform: rotateZ(-180deg);
transform: rotateZ(-180deg) ;
-webkit-transition: .35s ease-in-out;
-moz-transition: .35s ease-in-out;
-o-transition: .35s ease-in-out;
transition: .4s ease .4s;
opacity: 0;
}
#Pqb-icon span:nth-child(4) {
width: 5px;
height: 32%;
bottom: 10%;
left: 43%;
background: black;
border: 0px solid black;
-webkit-transform-origin: left center;
-moz-transform-origin: left center;
-o-transform-origin: left center;
transform-origin: left center;
}
#Pqb-icon.open span:nth-child(6) {
width: 5px;
height: 32%;
bottom: 10%;
left: 46.5%;
background: black;
border: 0px solid black;
-webkit-transform: rotateZ(-180deg);
-moz-transform: rotateZ(-180dreg);
-o-transform: rotateZ(-180deg);
transform: rotateZ(-180deg) ;
-webkit-transition: .35s ease-in-out .35s;
-moz-transition: .35s ease-in-out .35s;
-o-transition: .35s ease-in-out .35s;
transition: .4s ease .4s;
opacity: 0;
}
#Pqb-icon span:nth-child(5) {
bottom: 27%;
left: 51%;
border-radius: 25px;
-webkit-transform-origin: left center;
-moz-transform-origin: left center;
-o-transform-origin: left center;
transform-origin: left center;
}
#Pqb-icon span:nth-child(6) {
width: 5px;
height: 35%;
bottom: 40%;
left: 51%;
background: black;
border: 0px solid black;
-webkit-transform-origin: left center;
-moz-transform-origin: left center;
-o-transform-origin: left center;
transform-origin: left center;
}
Since you are only using transition and already have the toggleClass method, you don't need to change anything in the JS to reverse the transition effect. All that you need to do is add a different transition setting to the default state (not with class='open') like the below snippet.
Essentially what we are doing is this:
The elements that are causing the effect are the third, fourth, fifth and sixth span elements.
Initially for the move out effect, the fifth and sixth span elements move out with a delay of .4s.
The third and fourth span elements move out with a delay of 0.8s (or 0.9s). This has an extra delay because it has to move out after the fifth and sixth are out of the way. The fifth and sixth spans will take 0.4s (transition duration) + 0.4s (transition delay) = 0.8s to complete.
On toggling the class off, we need this to happen in reverse. That is, the third and fourth span elements should move in to view at a delay of 0.4s while the fifth and sixth span should move in after a delay of 0.8s. So adding the appropriate transition settings to the following selectors would be enough:
#Pqb-icon span:nth-child(3) {transition: .4s ease .4s;}
#Pqb-icon span:nth-child(4) {transition: .4s ease .4s;}
#Pqb-icon span:nth-child(5) {transition: .4s ease .9s;}
#Pqb-icon span:nth-child(6) {transition: .4s ease .9s;}
Note: I have removed the vendor prefixes in the snippet and added the prefix library to keep the code small.
$('#Pqb-icon').on('click', function() {
$(this).toggleClass('open');
});
#Pqb-icon {
background: white;
width: 170px;
height: 100px;
border-radius: 5px; /*dikte van rondjes*/
position: relative;
overflow: hidden;
border: 2px solid salmon;
border-bottom: 20;
transition: .9s ease-in-out;
}
#Pqb-icon span {
display: block;
position: absolute;
border: 5px solid black;
width: 20px;
height: 20px;
bottom: 50px;
left: 12%;
background: rgba(255, 200, 220, 0.4);
transition-timing-function: ease;
}
/* BEFORE collapsed: hamburger */
#Pqb-icon span:nth-child(1) {
left: 12%;
border-radius: 25px;
transition: .25s ease-in-out;
transform-origin: left center;
}
#Pqb-icon.open span:nth-child(1) {
left: 12%;
border-radius: 25px;
}
#Pqb-icon span:nth-child(2) {
width: 5px;
height: 38%;
bottom: 27%;
background: black;
border: 0px solid black;
transition: .25s ease;
transform-origin: left center;
}
#Pqb-icon.open span:nth-child(2) {
width: 5px;
height: 38%;
bottom: 27%;
background: black;
border: 0px solid black;
}
#Pqb-icon span:nth-child(3) {
bottom: 27%;
left: 28.5%;
border-radius: 25px;
transition: .4s ease .4s;
transform-origin: left center;
}
#Pqb-icon.open span:nth-child(3) {
left: 36%;
bottom: 50px;
border-radius: 25px;
transition: .4s ease .9s;
transform: translate(-40px, 0px);
opacity: 0;
}
#Pqb-icon span:nth-child(4) {
width: 5px;
height: 32%;
bottom: 10%;
left: 43%;
background: black;
border: 0px solid black;
transition: .4s ease .4s;
transform-origin: left center;
}
#Pqb-icon.open span:nth-child(4) {
width: 5px;
height: 38%;
bottom: 27%;
left: 15%;
background: black;
border: 0px solid black;
transition: .4s ease .9s;
transform: rotate(-180deg);
opacity: 0;
}
#Pqb-icon span:nth-child(5) {
bottom: 27%;
left: 51%;
border-radius: 25px;
transition: .4s ease .9s;
transform-origin: left center;
}
#Pqb-icon.open span:nth-child(5) {
bottom: 27%;
left: 46%;
border-radius: 25px;
transition: .4s ease .4s;
transform: rotateZ(-180deg);
opacity: 0;
}
#Pqb-icon span:nth-child(6) {
width: 5px;
height: 35%;
bottom: 40%;
left: 51%;
background: black;
border: 0px solid black;
transition: .4s ease .9s;
transform-origin: left center;
}
#Pqb-icon.open span:nth-child(6) {
width: 5px;
height: 32%;
bottom: 10%;
left: 46.5%;
background: black;
border: 0px solid black;
transition: .4s ease .4s;
transform: rotateZ(-180deg);
opacity: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<button type="button">
<span class="sr-only">Toggle navigation</span>
<div id="Pqb-icon">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</div>
</button>

Reveal Icon Button - Bootstrap 3

How to create a reveal icon inside button on hover in TB3. I tried to mimic this behavior using CSS transitions and position property. But I essentially need is to have a separate background color for icon and button. Here is what I am doing right now.
HTML Markup
<button class="btn btn-dark icon-revealed">
<span class="glyphicon glyphicon-cloud-download"></span>
Download
</button>
CSS Code
.btn.icon-revealed > span {
left: -30px;
width: 0;
-webkit-transition: all .5s ease-in-out;
-moz-transition: all .5s ease-in-out;
-o-transition: all .5s ease-in-out;
-ms-transition: all .5s ease-in-out;
}
.btn.icon-revealed:hover > span {
width: 20%;
-webkit-transform: translate(2em,0);
-moz-transform: translate(2em,0);
-o-transform: translate(2em,0);
-ms-transform: translate(2em,0);
}
What I want to Achieve
Notice the background color of icon and button changed on hover state. I could not able to do that. How can I achieve this in TB3?
Here's an alternative way that smooths out the transition.
.btn-dark {
border: none;
font-family: inherit;
font-size: inherit;
color: #fff;
background: none;
padding: 15px 30px;
display: inline-block;
text-transform: uppercase;
letter-spacing: 1px;
font-weight: 500;
outline: none;
position: relative;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
}
.btn-dark:after {
content: '';
position: absolute;
z-index: -1;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
}
.btn-icon {
background: #4E7878;
color: #fff;
line-height: 20px;
font-size: 14px;
overflow: hidden;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
backface-visibility: hidden;
}
.btn-icon span {
display: inline-block;
width: 100%;
height: 100%;
-webkit-transition: all 0.3s;
-webkit-backface-visibility: hidden;
-moz-transition: all 0.3s;
-moz-backface-visibility: hidden;
transition: all 0.3s;
backface-visibility: hidden;
}
.btn-icon:before {
background: #4A6B6B;
position: absolute;
height: 100%;
width: 30%;
line-height: 2.5;
font-size: 150%;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
}
.btn-download:hover span {
-webkit-transform: translateX(25%);
-moz-transform: translateX(25%);
-ms-transform: translateX(25%);
transform: translateX(25%);
color: #fff;
}
.btn-download:before {
left: -100%;
top: 0;
}
.btn-download:hover:before {
left: 0%;
}
.icon-reveal:before {
content: "\e197";
font-family: 'Glyphicons Halflings';
color: #fff;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<hr>
<div class="container">
<button class="btn-dark btn-icon btn-download icon-reveal"><span> Download</span>
</button>
</div>
You can create that effect using multiple backgrounds with linear-gradient. Code explanantion in comments
.btn.icon-revealed {
margin: 10px; /* Added for SO snippet, not required */
width: 115px; /* Added fixed width for avoiding jump */
}
.btn.icon-revealed > span {
left: -40px;
width: 0;
-webkit-transition: all .5s ease-in-out;
-moz-transition: all .5s ease-in-out;
-o-transition: all .5s ease-in-out;
-ms-transition: all .5s ease-in-out;
}
.btn.icon-revealed:hover > span {
width: 20%;
-webkit-transform: translate(2.5em, 0);
-moz-transform: translate(2.5em, 0);
-o-transform: translate(2.5em, 0);
-ms-transform: translate(2.5em, 0);
}
/* Added code */
.btn.icon-revealed {
background: #53777A;
color: #fff;
}
.btn.icon-revealed:hover {
background: linear-gradient(to right, #4B6B6E 0%, #4B6B6E 30%, #53777A 30%);
/* Start color---^, End at 30%-^, ^-- Start second color */
color: #fff;
}
.btn.icon-revealed:hover .text {
padding-left: 5px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<button class="btn btn-dark icon-revealed">
<span class="glyphicon glyphicon-cloud-download"></span>
<span class="text">Download</span>
</button>

slide up with transform3d with relative property

I am trying to slide up an element on a button click with css property transfrom: translate3d(0,-100px,0); but the element below having relative position is no sliding up with that element leaving some space.
First Container CSS Properties:
.setupContainer {
position: relative;
display: inline-block;
width: 100%;
height: 100px;
text-align: center;
background-color: rgba(23, 29, 97, 0.9);
color: #FFF;
cursor: default;
z-index: 1;
-webkit-transform: translate3d(0,-100px,0);
-moz-transform: translate3d(0,-100px,0);
-ms-transform: translate3d(0,-100px,0);
-o-transform: translate3d(0,-100px,0);
transform: translate3d(0,-100px,0);
-webkit-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-ms-transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
transition: all 300ms ease-in-out;
}
Second Container Css Properties:
.top_header {
position: relative;
width: 98%;
height: 165px;
background: #FFF;
margin: 0 auto;
float: none;
clear: both;
top: 1%;
text-align: center;
margin-bottom: 3px;
border-bottom: 2px solid #8CC5A7;
}

Resources