Flex sidebar: how to grow to 100% of height

前端 未结 3 1824
小鲜肉
小鲜肉 2021-01-25 13:42

I´m building a sidebar using CSS flex and I need it to grow vertically to fill the whole screen vertical height. Here is a skeleton of what I´m doing.

JSFiddle here

3条回答
  •  抹茶落季
    2021-01-25 14:13

    I think I got it pretty close by assigning the full viewport height to your container and then removing flex: 1 from .content children.

    .app {
      display: flex;
      flex-direction: row;
      . align-items: flex-start;
      height: 100vh;
      width: 100%;
    }
    
    .sidebar {
      background-color: red;
    }
    
    .content {
      width: 100%;
      display: flex;
      flex-direction: column;
    }
    
    .content-header {
      background-color: grey;
    }
    
    .content-main {
      background-color: yellow;
    }
    Content Header
    This is the main content

提交回复
热议问题