How can I have a position: fixed; behaviour for a flexbox sized element?

前端 未结 5 1658
醉梦人生
醉梦人生 2020-12-02 10:09

I have a div called .side-el which I would like to have in a position: fixed; behavior, but as soon as I apply position fixed the width alternates from the right one. The ri

5条回答
  •  旧巷少年郎
    2020-12-02 10:51

    @Daniel , I know this is very late but ... while the accepted answer is correct, I don't feel it's very helpful. I had the same question (which is how I came across this post), and the solution I think I'll go with is to wrap the position fixed element within the flex element. Here's a (very ugly) example

    Relevant Markup

      
    

    Relevant CSS

    .Layout-aside {
      order: 0;
      min-width: 140px;
      width: 140px;
      background-color: rgba(0, 255, 0, .4);
      transition: width .4s, min-width .4s; 
    }
    .Layout-aside.isCollapsed {
      min-width: 25px;
      width: 25px;
    }
    
    .Layout-aside-inner {
      position: fixed;
    }
    
    .Layout-aside.isCollapsed .Layout-aside-inner {
      width: 25px;
    }
    
    .Layout-aside.isCollapsed .Layout-aside-content {
      opacity: 0;
    }
    

提交回复
热议问题