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?
Max-width and min-width can be used together to target a specific range of screen sizes. @media only screen and (max-width: 600px) and (min-width: 400px) {...} The query above will trigger only for screens that are 600-400px wide. This can be used to target specific devices with known widths.
The min-width and max-width are media features that correspond to a certain media type that has been specified in the media query. The min-width specifies the minimum screen width of a specific device, meanwhile, The max-width media feature states the maximum screen width of a specific device.
Keeping track of how things appear across multiple screen sizes may be challenging, but the max-width, min-width and max-height, and min-height properties help tackle these challenges. These properties let you adjust the size of elements without needing to use media queries.
The min-width property in CSS is used to set the minimum width of a specified element. The min-width property always overrides the width property whether followed before or after width in your declaration. Authors may use any of the length values as long as they are a positive value.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With