Evenly distribute images vertically within fixed-height space

后端 未结 2 1651
心在旅途
心在旅途 2020-12-30 14:29

I have 3 images vertically aligned in fixed height div. How can I make sure that the top and bottom padding between them remains even when an image is added or deleted.

2条回答
  •  自闭症患者
    2020-12-30 14:47

    I know I'm bound to stumble across this again the next time I search for it. Leaving this as a reference for myself. Difference is elements don't have to have fixed heights per-se:

    http://codepen.io/anon/pen/ojBPaq?editors=110

    HTML

    • wefwfwefww efwefwfwfewfwef wefwfwf wefwfe wefwf wefwfwfwfwf wef wefwfe

    CSS

    * { box-sizing: border-box; }
    
    ul {
      list-style: none;
      margin: 0;
      padding: 0;
      background: grey;
      width: 500px;
      height: 400px;
      display: table;
    }
    
    li {
      display: table-row;
      background: aqua;
      vertical-align: bottom;
    }
    
    .tile-wrap {
      display: table-cell;
      vertical-align: middle;
    }
    
    .one {
      vertical-align: top;
    }
    
    .two {
      vertical-align: middle;
    }
    
    .three {
      vertical-align: bottom;
    }
    
    .tile-wrap .tile {
      width: 100px;
      min-height: 100px;
      background: white;
      border: 1px solid blue;
    
    }
    

提交回复
热议问题