Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply transition by using min-width and max-width together

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?

like image 489
Umer Hassan Avatar asked May 25 '16 17:05

Umer Hassan


People also ask

Can we use max width and min width at the same time?

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.

How does min width and max width work?

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.

In what way does the min width max width min-height and max height help in web development?

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.

Does width override min width?

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.


1 Answers

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;
}
like image 136
G-Cyrillus Avatar answered Nov 11 '22 13:11

G-Cyrillus