CSS: auto height on containing div, 100% height on background div inside containing div

前端 未结 9 977
忘了有多久
忘了有多久 2020-12-22 20:10

The problem, is that I have a content div which stretches its container height-wise (container and content div have auto height).

I want the background container,

9条回答
  •  攒了一身酷
    2020-12-22 20:59

    Make #container to display:inline-block

    #container {
      height: auto;
      width: 100%;
      display: inline-block;
    }
    
    #content {
      height: auto;
      width: 500px;
      margin-left: auto;
      margin-right: auto;
    }
    
    #backgroundContainer {
      height: 200px; /*200px is example, change to what you want*/
      width: 100%;
    }
    

    Also see: W3Schools

提交回复
热议问题