jQuery .show() a flex box

前端 未结 9 1275
南笙
南笙 2021-02-06 20:56

I have an element with a flexbox

    div#myFlexbox{ display:flex; }

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

9条回答
  •  暖寄归人
    2021-02-06 21:33

    The class solution works, yes. Here's a different approach I came up with:

    Javascript Function

    function showFlex(element) {
    
        var flexContainer = document.getElementById(element);
    
        flexContainer.setAttribute("style", "display: -webkit-box; display: -ms-flexbox; display: -webkit-flex; display: flex;");
    }
    

    To use it:

    showFlex( "yourIDhere" );
    

    Note that the ID doesn't need the # when you call the function.

    Example:

    https://codepen.io/florantara/pen/aLeyYb/

提交回复
热议问题