Is it possible for inline-block element to auto fill the available width?

后端 未结 4 1943
悲&欢浪女
悲&欢浪女 2021-02-07 15:13

I have a

, which contains
and
, which themselve
4条回答
  •  情歌与酒
    2021-02-07 15:55

    You have to remove the inline-block styles and float the #sub-navigation div. inline-block is not suited for what you are trying to achieve. When you add no display styles, the div element will be the default value which is block, block elements take up all the available space by default. By floating the #sub-navigation element you make it only take up the space required for its contents.

    #sub-navigation {
      width: 200px; 
      height: 150px; 
      float : left;
      vertical-align: top; 
      background-color: forestgreen; 
      color: white;
    }
    
    #main-container {
      padding: 10px;        
      overflow: auto; 
      background-color: yellow;
    }
    

    make sure to add a clear: left element after the #main-container

提交回复
热议问题