Div background-color does not extend to child divs

前端 未结 5 1767
不知归路
不知归路 2021-01-28 12:21

I have a container div with several child divs within this. The parent div has a background-color, however, this doesn\'t seem to be extending to the last couple of child divs.

5条回答
  •  情深已故
    2021-01-28 12:52

    You need to add

    after the last floating element within the parent div.

    Your new codes becomes this:

    body {
      background-color: #F8F8F8;
      font-family: 'Open Sans', sans-serif;
      text-transform: uppercase;
    }
    
    .container {
      display: block;
      max-width: 600px;
      height: 100%;
      margin: 20vh auto;
      padding: 0 3%;
      background-color: green;
      text-align: justify;
    }
    
    h1 {
      font-size: 1em;
      letter-spacing: 1px;
      font-weight: 700;
      padding-top: 20px;
    }
    
    ul {
      margin: 0;
      padding: 0;
    }
    
    .inline-row {
      display: inline-block;
      height: 56px;
      vertical-align: top;
    }
    
    li {
      list-style-type: none;
      margin: 20px auto;
    }
    
    .image-container {
      width: 24%;
      img {
        width: 100%;
        height: auto;
      }
    }
    
    .product {
      width: 58%;
    
      h2 {
        margin: 0;
        padding: 0;
        line-height: 28px;
        vertical-align: top;
      }
      p {
        margin: 0;
        padding: 0;
        line-height: 28px;
      }
    }
    
    .cost {
      width: 13%;
      text-align: right;
      p {
        margin: 0;
        padding: 0;
        line-height: 28px;
      }
    }
    
    .delete {
      float: right;
      width: 3%;
      text-align: right;
      font-size: 0.7em;
      font-weight: 700;
      line-height: 28px;
      cursor: pointer;
    }
    
    hr {
     margin-top: 30px;
    }
    
    .checkout {
      display: block;
      margin-top: 10px;
      width: 50%;
      float: right;
    }
    
    .left {
      display: block;
      width: 55%;
      float: left;
      line-height: 40px;
      text-align: right;
    }
    
    .right {
      display: block;
      width: 40%;
      margin: auto;
      float: right;
      cursor: pointer;
    }
    
    .button {
      height: 40px;
      width: 100%;
      border: 1px black solid;
      border-radius: 20px;
      text-align: center;
      line-height: 40px;
      font-weight: 700;
    }
    .clear{
      clear:both;
    }

    Shopping Cart

    • barolo.

      barolo di castiglione falletto

      39.99 EUR

      X
    • barolo.

      barolo di castiglione falletto

      39.99 EUR

      X
    • barolo.

      barolo di castiglione falletto

      39.99 EUR

      X

    TOTAL 148.98 EUR
    CHECKOUT

    Example here: https://jsfiddle.net/22L7engy/

提交回复
热议问题