I have a nav bar for which I'm trying to make the toggle button work, my toggle button is a checkbox, so following is the css to make the navbar (#navbar-left) appear when you click on the checkbox
#navbar-left{
max-width: 0;
min-width: 0;
width: 0;
transition: max-width 0.2s ease;
transition: min-width 0.2s ease;
}
.nav-trigger:checked ~ #navbar-left {
max-width: 200%;
min-width: 20%;
width: auto;
float: left;
}
where .nav-trigger is the check button, I have been able to either close the navbar smoothly using transition or open the navbar smoothly using transition by applying min-width or max-width at a time, but how can I use them both to open and close the navbar smoothly using the transitions.
I cannot simple apply the transitions using width property because I've to always set the width property to auto.
What would be the best solution or any alternate way to achieve this?
It should be written within one single rule :
https://developer.mozilla.org/en-US/docs/Web/CSS/transition
The transition CSS property is a shorthand property for transition-property, transition-duration, transition-timing-function, and transition-delay. It enables you to define the transition between two states of an element. Different states may be defined using pseudo-classes like :hover or :active or dynamically set using JavaScript.
#Syntaxe
/* Apply to 1 property */
/* property name | duration */
transition: margin-left 4s;
/* property name | duration | delay */
transition: margin-left 4s 1s;
/* property name | duration | timing function | delay */
transition: margin-left 4s ease-in-out 1s;
/ * Apply to 2 properties * /
transition: margin-left 4s, color 1s;
/* Apply to all changed properties */
transition: all 0.5s ease-out;
/* Global values */
transition: inherit;
transition: initial;
transition: unset;
#navbar-left{
max-width: 0;
min-width: 0;
width: 0;
transition: max-width 0.2s ease,min-width 0.2s ease;
}
.nav-trigger:checked ~ #navbar-left {
max-width: 200%;
min-width: 20%;
width: auto;
float: left;
}
Related
This question already has answers here:
CSS3 transition doesn't work with display property [duplicate]
(7 answers)
Closed 4 years ago.
My code transition and transform is not works.
My CSS
div.panel {
display: none;
}
div.panel.show {
display: block !important;
}
.panel.show .text-light{
transform:translateY(10%);
background:red;
transition-delay:3s;
}
full code is here. Thanks for your help
Try this
div.panel .text-light{
width: 0;
height: 0;
opacity: 0;
}
div.panel.show .text-light{
width: 100%;
height: 100%;
opacity: 1;
}
.panel.show .text-light{
transform:translateY(10%);
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
background:red;
}
The problem with your code was that you were applying transition to the element whose styles were not getting changed by the code you wrote. The transition will work only if there is some change in css on the element where you are applying the transition.
Transition animates the process of changing state1 to state1.
First of all you should set property transition and set which parameter to animate, how long. Then optional - type of animation(ease, ease-in-out so on), delay and more you can find here https://www.w3schools.com/cssref/css3_pr_transition.asp.
Then you need to change that property which you want to animate. For example
.animated {
background-color: #eee;
border: 2px dashed black;
border-radius: 5px;
width: 100px;
height: 100px;
/*
this is your transition for background-color
also you could set 'all' insted of propety which will animate any change of element
*/
transition: background-color .5s ease;
}
/* There is a second state which we want to apply a transition to */
.animated:hover {
background-color: #e6e;
}
<div class="animated">
Hover me
</div>
CODE SAMPLE HERE: http://codepen.io/colbisaurusrex/pen/YZdKyO?editors=1100
First problem:
I am trying to smoothly expand and compress a div (class: event) on hover. It expands smoothly, but it snaps back quickly when user is no longer hovering on div. I'd like to transition back at the same ease as it expands
Second problem:
Simultaneously, I'd like to reveal an inner, hidden child(class: hidden) when I hover over its parent(class: event). Ideally, I'd like to reveal it when the parent is fully expanded. And ease it back to hidden as the parent compresses. Right now, it is revealed immediately, before the parent div is fully expanded. I have tried to add a delay.
Basically, there is a beginning and ending transition that exact mirrors of each other. I'd like to do this with no Javascript
Bonus Question: If the entire transition was set off by a button click(say the Show Details button), do I have to use JS? Is there a way to do this with CSS only?
/* This is the CSS I am working with */
.event {
margin-top: 2%;
width: 960px;
border-color:#496DD9;
border-style: dotted;
font-size: 0.5em;
height: 250px;
transform: height 300ms ease-out;
}
.event:hover {
height: 300px;
transition: height 500ms ease-in;
}
.event:hover .hidden {
display: block;
transition: display 300ms ease-in 1s;
}
.hidden {
font-size: 30px;
display: none;
}
/* End of css */
problem 1: transform should be transition
.event {
margin-top: 2%;
width: 960px;
border-color:#496DD9;
border-style: dotted;
font-size: 0.5em;
height: 250px;
transform: height 300ms ease-out; // change this to transition
}
Problem 2: try using opacity instead of display:
.event:hover .hidden {
/* display: block; */
/* transition: display 500ms ease-in 1s; */
-webkit-transition: opacity 2s ease-in-out;
opacity: 1;
}
.hidden {
font-size: 30px;
/* display: none; */
opacity: 0;
}
demo: http://codepen.io/anon/pen/NpeWZz?editors=1100
I have two transitions set for #circle.
I want only the opacity to have a delay, but I can only make it where both of the transitions do.
My full goal is to make the opacity change when the circle is mid spin (so at exactly 90deg).
But I will work out the timing myself, I just want to know how to give the delay to only one transition.
#circle {
background-color:black;
background-image:url('rain.img');
height:300px;
width:300px;
border-radius:100%;
margin:0 auto;
perspective:1000;
transition:transform 2s, opacity .1s;
}
#circle:hover {
perspective:1000px;
transform:rotateY(180deg);
opacity:.25;
}
I imagine you will only need to see the CSS, but if you think you need to see the full code go here ===> https://jsfiddle.net/z49kd9qk/
Any help would be appreciated, thanks!
Solution
The transition-delay function can only be parsed as the second timing value.
Instead of this:
transition: transform 2s, opacity .1s;
Work with this:
transition: transform 2s 0s, opacity 0s 2s;
Explanation
When working with the transition shorthand property, the order and presence of components matter. Here's the basic order and composition:
<transition-property> <transition-duration> <transition-timing-function> <transition-delay>
If the transition-property component is left out, the shorthand property applies all.
If the transition-timing-function component is left out, the shorthand applies ease.
(Both are the initial values of the respective properties.)
So you can minimize the declaration to this:
<transition-duration> <transition-delay>
If only one value is declared (like in your code), it will always be applied to transition-duration.
So with this:
transition: transform 2s, opacity .1s;
... you're applying a timing duration to both properties.
The transition-delay function can only be parsed as the second timing value.
Per your question:
I want only the opacity to have a delay but I can only make it where both of the transitions do.
Then do this instead:
transition: transform 2s 0s, opacity 0s 2s;
revised fiddle
#circle {
background-color: black;
background-image: url('https://media.giphy.com/media/eNMHeFodYv8Os/giphy.gif');
height: 300px;
width: 300px;
border-radius: 100%;
margin: 0 auto;
perspective: 1000;
/* transition:transform 2s, opacity .1s; */
transition: transform 2s 0s, opacity 0s 2s;
}
#circle:hover {
perspective: 1000px;
transform: rotateY(180deg);
opacity: .25;
}
#cloud {
height: 70px;
padding: 10px;
position: relative;
left: 10%;
top: 105px;
}
#temp {
font-family: 'Slabo 27px', serif;
position: relative;
left: 45%;
font-size: 100px;
bottom: 100px;
color: white;
}
<div id='circle'>
<img src='http://www.freeiconspng.com/uploads/rain-cloud-icon-5.png' id='cloud'>
<h2 id='temp'>54°</h2>
</div>
Following coding is to expand Div when mouse hover its space using CSS transition. The problem is height in that transaction can be defined specific height. Defining specific height can be workable for only desktop version but for mobile version, that's gonna be problem.
For desktop version, specific list in is three columns thus defining specific height is Ok. For mobile version, I merge these three column to be one column thus defining specific height is not ok.
div.mycolumn {
max-height: 0;
transition: max-height 0.15s ease-out;
overflow: hidden;
background: #d5d5d5;
}
div.mycolumn:hover {
max-height: 500px; <<<< WANT AUTO HEIGHT INSTEAD
transition: max-height 0.25s ease-in;
}
My question it AngularJs can be get specific height of current Div and pass it into CSS, (i'm using LESS instead.)
div.mycolumn
.container
.row
.col-xs-4.col-sm-12
.row(data-ng-repeat="data in mydata1")
.col-xs-12.col-sm-12.col-md-3
{{data.myname}}
.col-xs-4.col-sm-12
.row(data-ng-repeat="data in mydata2")
.col-xs-12.col-sm-12.col-md-3
{{data.myname}}
.col-xs-4.col-sm-12
.row(data-ng-repeat="data in mydata3")
.col-xs-12.col-sm-12.col-md-3
{{data.myname}}
.category-box {
max-height: 0;
transition: max-height 0.5s ease-out;
overflow: hidden;
}
//For Mobile
.category-box {
&.show {
max-height: 999px;
transition: max-height 0.5s ease-in;
}
}
//For Desktop
#media screen and (min-width: 48em){
.category-box {
&.show {
max-height: 500px;
transition: max-height 0.5s ease-in;
}
}
}
Above codes are workable for my question.
There are couple of similar questions around. But here's a little change in the case.
I am using CSS3 transition to show a small div in the bottom of the page. When I set the class .show, it slides up and when I remove it, it slides down and goes out of the page.
.bar {
transition: bottom 0.3s ease-out, opacity 0.3s;
opacity: 0;
bottom: -44px;
}
.bar.show {
opacity: 0.85;
bottom: 0;
transition: bottom 0.3s ease-out, opacity 0.3s;
}
My problem is, though it goes away, it still is a display:block element. Which causes my body have scroll. Is there any way by which I can set display:none (using CSS only) after transition? Or some how convince body not to have scroll? (I already have overflow: hidden).
Since transition-delay don't work on display property. I tried visibility, but still the browser keeps some space for scroll.
Update:
Just incase we don't find any good solution, I've done it this way for now instead of display: none.
.bar {
transition: max-height 0s linear 0.3s, bottom 0.3s ease-out, opacity 0.3s;
opacity: 0;
bottom: -44px;
max-height: 0;
overflow: hidden;
border-top-width: 0;
padding: 0;
}
.bar.show {
opacity: 0.85;
bottom: 0;
max-height: 50px;
padding: 5px;
border-top-width: 1px;
transition: bottom 0.3s ease-out, opacity 0.3s;
}
Here's something that could be useful, I've essentially implemented this via position:fixed, check this fiddle to see if it's something that meets your requirements - http://jsfiddle.net/7x0oajv2/
Second approach could be using position:absolute with a overflow:hidden on the body like so - http://jsfiddle.net/7x0oajv2/1/
I would try to set the margin as following:
height of the division = x
margin-bottom: -x;
Not sure if this works but I think it should. Otherwise you might use
position: fixed;
Or the third possible solution would be to not let the division slide out at the bottom but on the left side. This can be done like this:
.bar {
transition: bottom 0.3s ease-out, opacity 0.3s;
opacity: 0;
left: -100px;
}
If you want to change CSS dynamically you must use JavaScript or jQuery to change DIVs property.
E.g
$.("#myDiv").removeClass('displayBLOCK');
$.("#myDiv").addClass('displayNONE');
CSS:
.displayNONE{
display: none;
}
.displayBLOCK{
display: block;
}
If you just want to remove the div, call $.('#myDiv').hide(). You don't need to set display property to "none".