2017-05-02 66 views
1

我有一個列表顯示了用戶的分數。垂直對齊徽章與css

Align

這是我的HTML。我希望每個值都一致。我嘗試了不同的選項,例如使用表格和使用網格。我無法這樣實施。徽章永遠不會對齊。我終於可以通過absolute來實現它的定位。但那不是迴應。

<div class="inner-counter"> 
     <div class="profile-credits"> 
     <span class="credit">{{auth.user?.hdc}}</span> 
     <span > 
      <div class="badges" style="background-color: #ffcc00"></div> 
     </span> 
     <span class="counter-text"> 
      Books hunted 
     </span> 
     </div> 
     <div class="profile-credits"> 
     <span class="credit">{{auth.user?.ohc}}</span> 
     <span> 
      <div class="badges" style="background-color: #ABBBC2"></div> 
     </span> 
     <span class="counter-text"> 
      Own hunts 
     </span> 
     </div> 
     <div class="profile-credits"> 
     <span class="credit">{{auth.user?.hgc}}</span> 
     <span> 
      <div class="badges" style="background-color: #cc9966"></div> 
     </span> 
     <span class="counter-text"> 
      Books hunting 
     </span> 
     </div> 
    </div> 

這裏是絕對定位的CSS。

.badges{ 
    display: inline-block; 
    height: 8px; 
    width: 8px; 
    border-radius: 4px; 
    margin-left: 4px; 
    } 
    .counters{ 
    text-align: center; 
    vertical-align: middle; 
    margin-top: 30px; 
    margin-left: 15%; 
    } 
    .counter-text { 
    padding-left: 10px; 
    } 
    .profile-credits{ 
    padding-top: 10px; 
    .credit{ 
     text-align: right; 
     position: absolute; 
     right: 70%; 
    } 
    } 
    .inner-counter{ 
    text-align: left; 
    display: inline-block; 
    } 

我該怎麼辦呢沒有信用的絕對定位。每列都是左對齊的?

+0

•有時,如果是行內的子彈,你可以只使用UTF-8子彈將被正確對齊文本,你只需要放大字體。代碼:'•'• – Troyer

回答

4

https://jsfiddle.net/RemyaJ/n19hdzs6/4/

.inner-counter { 
     display:table; 
     } 
     .profile-credits { 
     display:table-row; 
     } 
    } 
    .badge-wrap { 
     display: table-cell; 
    } 
    .badges{ 
    height: 8px; 
    width: 8px; 
    border-radius: 4px; 
    margin-left: 4px; 
    } 
    .counters{ 
    text-align: center; 
    vertical-align: middle; 
    margin-top: 30px; 
    margin-left: 15%; 
    } 
    .counter-text { 
    padding-left: 10px; 
    display: table-cell; 
    } 
    .profile-credits{ 
    padding-top: 10px; 

    } 
    .credit{ 
     text-align: right; 
    display: table-cell; 
    } 
    .inner-counter{ 
    text-align: left; 
    display: inline-block; 
    }  
3

基本上你的credit -class的寬度設置爲您所需的寬度。

這裏有一個工作版本:

https://codepen.io/selbekk/pen/xdrRNp

另一種方法是通過使用css-gridflexbox,但這將是最快的勝利(因爲你知道有多大這個學分數量可以)。

這裏是你如何做同樣的事情與flexboxhttps://codepen.io/selbekk/pen/rmwjOz

+0

如果你添加更多的數字,這將推動徽章以及文字 –

+0

是的,我也注意到了。也許網格解決方案是最好的 - 給定相同的HTML結構。 –

0

有沒有對齊,因爲你的數字可能會增長,並推動徽章。 你需要讓你的號碼單元一起成長。

您也可以查看您的演示文稿,並將該數字放在最後。這樣你就沒有更多的問題。

0

我看到最好的方法是將數字放在容器內,並將徽章與另一個容器中的文本放在一起,這樣每次數字變大時都會推動整個容器,並且它將始終像這樣對齊

enter image description here