代码之家  ›  专栏  ›  技术社区  ›  William Entriken

排列不同尺寸的徽章

  •  0
  • William Entriken  · 技术社区  · 8 年前

    我有几个代表用户的徽章。一些用户有照片( display: block )其他只是文字( display: inline ).

    enter image description here

    对于容器,我们有:

    <div class="align-self-center">
    

    每一项都是这样的:

    <div style="height:30px" class=" pl-0 pt-0 pb-0 mr-1 mt-1 badge badge-danger">
      <span class="p-1">PMT</span>
      <span class="align-self-center">46h </span>
    </div>
    

    请告知我们如何正确垂直对齐所有项目。

    代码笔: https://codepen.io/anon/pen/EbYJyd?editors=1100#0

    4 回复  |  直到 8 年前
        1
  •  2
  •   sol    8 年前

    添加 display: flex 然后涂抹在容器上 align-items 所有物要垂直对齐每个div中的项目,请对 div .

    .profiles,
    .profiles div {
      display: flex;
      align-items: center;
    }
    <html>
    
    <head>
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
    </head>
    
    <body>
      <div class="profiles">
        <div style="height:30px" class=" pl-0 pt-0 pb-0 mr-1 mt-1 badge badge-danger"><span class="p-1">PMT</span><span>46h </span></div>
        <div style="height:30px" class=" pl-0 pt-0 pb-0 mr-1 mt-1 badge badge-danger"><img height="30" title="debbcarol not online on Slack" class="rounded translucent" src="https://avatars.slack-edge.com/2017-06-01/191787258759_1f147d9c455250f2399c_72.jpg"> <span>8d </span></div>
        <div style="height:30px" class="pl-0 pt-0 pb-0 mr-1 mt-1 badge badge-danger"><span class="p-1">David</span><span>8d </span></div>
        <div style="height:30px" class=" pl-0 pt-0 pb-0 mr-1 mt-1 badge badge-danger"><img height="30" title="robgarza" class="rounded" src="https://avatars.slack-edge.com/2016-11-05/100970331412_61a091a494a137be0188_72.png"> <span>3d </span></div>
        <div style="height:30px" class=" pl-0 pt-0 pb-0 mr-1 mt-1 badge badge-danger"><img height="30" title="alinan523" class="rounded" src="https://avatars.slack-edge.com/2017-07-11/211053436291_0695a1cedc52065260b5_72.png"> <span>28d </span></div>
        <div style="height:30px" class=" pl-0 pt-0 pb-0 mr-1 mt-1 badge badge-danger"><img height="30" title="will not online on Slack" class="rounded translucent" src="https://avatars.slack-edge.com/2016-10-20/93977971973_091d34c1388d122e488e_72.jpg"> <span>21d </span></div>
      </div>
    </body>
    
    </html>
        2
  •  1
  •   David Wilkinson    8 年前

    我利用了 display: inline-block 在这里的包装上实现您的目标: https://codepen.io/anon/pen/oovOdN?editors=1100#0 .

    div.pl-0 {
        display: inline-block;
        vertical-align: middle;
    }
    

    使用 inline-block ,我可以利用 vertical-align 属性垂直居中。

        3
  •  1
  •   designtocode    8 年前

    float: left 到 .badge

    在此处查看更新的代码笔 https://codepen.io/msbodetti/pen/NwKmzw?editors=1100

        4
  •  0
  •   holden    8 年前

    .badge {
    display: inline-block;
    padding: .25em .4em;
    font-size: 75%;
    font-weight: 700;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    vertical-align: baseline; <-- eliminate this
    vertical-align: top; <-- add this
    border-radius: .25rem;
    }