Center and bottom-align flex items

后端 未结 3 1808
悲&欢浪女
悲&欢浪女 2020-11-22 00:35

I have a flex container (the blue square) with the following properties:

display: flex;
justify-content: center;
align-items: center;
flex-wrap: nowrap;
         


        
3条回答
  •  执笔经年
    2020-11-22 00:58

    let the container with position: relative and the green square with position:absolute;

    body {
      margin: 0;  
    }
    
    #container {
      display: flex;
      justify-content: center;
      align-items: center;
      flex-wrap: nowrap;
      width: 192px;
      height: 192px;
      border: 4px solid indigo;
      position: relative;
      background: lavender;
    }
    
    .blue {
      margin: 10px;
      width: 30px;
      height: 30px;
      outline: 4px solid skyblue;
      background: honeydew;
    }
    
    #green {
      position: absolute;
      width: 30px;
      height: 30px;
      left: 0;
      right: 0;
      margin: auto;
      bottom: 20px;
      outline: 4px solid yellowgreen;
      background: greenyellow;
    }

提交回复
热议问题