How to make a div fill a remaining horizontal space?

前端 未结 25 1779
野的像风
野的像风 2020-11-22 00:45

I have 2 divs: one in the left side and one in the right side of my page. The one in the left side has fixed width and I want the one of the right side to f

25条回答
  •  萌比男神i
    2020-11-22 01:43

    Simplest solution is to just make the left div width equal 100% - the width of the right div plus any margin between them.

    
    
    .cont{
      display: inline-grid;
      grid-template-columns: 160px 10px calc(100% - 170px);
      grid-template-rows: auto;
      grid-template-areas: "search .  navigation";
      width: 100%;
      height: auto;
      text-align: center;
    }
    
    .search {
      grid-area: search;
      height: 90px;
      background-color: #00FF00;
      line-height: 80px;
      font-size: 1.4rem;
      font-weight: 600;
    }
    nav {
      grid-area: navigation;
      height: 90px;
      background-color: #A53030;
    }
    
    .navbar{
      display: flex;
      height: 30px;
      width: 100%;
      padding: 0%;
      list-style-type: none;
      flex-flow: row wrap;
      flex: 0 1 auto;
      justify-content: space-between;
      align-content: flex-start;
      align-items: flex-start;
    }
    
    .navbar a{
        outline: 0;
        text-decoration: none;
    }
    

    https://codepen.io/tamjk/pen/dybqKBN

提交回复
热议问题