代码之家  ›  专栏  ›  技术社区  ›  David Kris

带flexbox柱的定心圆

  •  0
  • David Kris  · 技术社区  · 8 年前

    下面是我试图使用flexbox创建的布局的代码。与其让圆圈位于第二列上方的中心,是否可以使其与第一列居中,并在调整屏幕大小时保持居中?我需要采取什么步骤来实现这样的目标?任何有帮助的,谢谢。这是 CodePen

    .profile-picture {
      display: flex;
      margin-top: 55px;
      margin-bottom: 35px;
      display: inline-block;
      width: 150px;
      height: 150px;
      border-radius: 50%;
      background-repeat: no-repeat;
      background-position: center center;
      background-size: cover;
      background-color: #f1f1f1;
    }
    
    .image {
      background-image: url('');
    }
    
    .profile-bio {
      background-color: #f1f1f1;
      text-align: center;
      line-height: 75px;
      font-size: 30px;
      height: 150px;
      width: 550px;
      align-items: center;
      justify-content: center;
      display: flex;
    }
    
    .profile-bio:before {
      content: '';
      float: left;
      padding-top: 100%;
    }
    
    .flex-container {
      display: flex;
      justify-content: center;
    }
    
    .flex-post {
      background-color: #f1f1f1;
      margin: 10px;
      text-align: center;
      line-height: 75px;
      font-size: 30px;
      flex: 1 0 auto;
      height: auto;
      max-width: 275px;
      align-items: center;
      justify-content: center;
      display: flex;
    }
    
    .flex-post:before {
      content: '';
      float: left;
      padding-top: 100%;
    }
    
    .flex-post:hover {
      background-color: rgba(1, 1, 1, 0.5);
    }
    <div class="flex-container">
      <div class="profile-picture image">
      </div>
    </div>
    
    <div class="flex-container">
      <div class="flex-post"></div>
      <div class="flex-post"></div>
      <div class="flex-post"></div>
    </div>
    <div class="flex-container">
      <div class="flex-post"></div>
      <div class="flex-post"></div>
      <div class="flex-post"></div>
    </div>
    <div class="flex-container">
      <div class="flex-post"></div>
      <div class="flex-post"></div>
      <div class="flex-post"></div>
    </div>
    1 回复  |  直到 8 年前
        1
  •  1
  •   t3ol5    8 年前

    给你

    CodePen

    使用此处使用的百分比值,可以得到相对于 containing block 。

    你可以把所有的 flex-post 在一个 flex-container 使用此css:

    .flex-container {
      display: flex;
      flex-flow: row wrap;
    }
    
    .flex-post { 
      width: 30%;
      margin-right: 5%;
      margin-bottom: 5%;
      background-color: #f1f1f1;
    }
    
    .flex-post:nth-child(3n+3) {
      margin-right: 0;
    }
    
    .flex-post:nth-last-child(1),
    .flex-post:nth-last-child(2),
    .flex-post:nth-last-child(3) {
      margin-bottom: 0;
    }