CSS Right Margin Does Not Work Inside a Div With Overflow Scroll

后端 未结 3 1137
鱼传尺愫
鱼传尺愫 2020-12-04 17:34

I am trying to make two divs, one inside the other. The inner div is larger than the outer div, the outer div has overflow:scroll, and the inner div has m

3条回答
  •  庸人自扰
    2020-12-04 18:29

    So the answers here don't actually solve the problem! (Although super detailed to the reason why it doesn't work)

    I needed a solution. Here's mine for future readers. Use a combination of display:flex; with pseudo ::after element to fake the presence of a div to provide the margin needed.

    .wrapper {
      display: flex;
      width: 400px;
      height: 100%;
      padding: 40px;
      background: lightGrey;
    }
    
    .lists_container {
      display: flex;
      flex-direction: row;
      justify-content: flex-start;
      overflow: auto;
      position: relative;
      background: grey;
      padding: 40px;
      margin: 40px;
      width: 100%;
    }
    
    .card {
      position: relative;
      display: flex;
      flex-direction: column;
      justify-content: center;
      min-width: 250px;
      max-width: 500px;
      height: 100px;
      margin: 50px 0;
      padding: 20px;
      background: orange;
      margin-right: 30px;
    }
    
    .card.last::after {
      content: '';
      position: absolute;
      right: -100px;
      width: 40px;
      height: 100%;
      background: red;
    }

提交回复
热议问题