Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery .show() a flex box

I have an element with a flexbox

<ul id="myFlexbox">  div#myFlexbox{     display:flex; } 

after hide it and show it, it gets messed up.

$('#myFlexbox').show(); 

now the element has a display of block instead of flex.

<ul id="myFlexbox" style="display: block;"> 

How can I use .hide and .show with flexboxes?

like image 794
Running Buffalo Avatar asked Jul 20 '16 22:07

Running Buffalo


People also ask

What does show () do in jQuery?

The show() Method in jQuery is used to display the hidden and selected elements. Note: This method display the hidden elements which are using CSS display: none property. The elements are not visible whose visibility is hidden.

What happens when display is Flex?

A flex container expands items to fill available free space or shrinks them to prevent overflow. Most importantly, the flexbox layout is direction-agnostic as opposed to the regular layouts (block which is vertically-based and inline which is horizontally-based).


1 Answers

The show() adds display:block as a default for div. You can change the display to flex using jQuery css():

$('#myFlexbox').css('display', 'flex'); 
like image 80
guizo Avatar answered Sep 27 '22 20:09

guizo