[英]How can I align text to the top and the bottom of the same div css?
我正在嘗試將一行文本對齊到圖像的頂部,也對齊到圖像的底部。
這是一個小矮人
****** Name
******
****** More Info
<div class="row">
<div class="col-md-4">
<img src="https://graph.facebook.com/102031900129645/picture?type=square&redirect=true&width=100&height=100">
<span>John Smith</span>
<br>
<span>10 friends</span>
</div>
</div>
您可以嘗試以下方法:
.col-md-4 {
position: relative;
}
.col-md-4 span {
position: absolute;
top: 0;
}
.col-md-4 span:last-child {
top: auto;
bottom: 0;
}
工作演示
.col-md-4 { position: relative; } .col-md-4 .name { position: absolute; top: 0; } .col-md-4 .info { position: absolute; bottom: 0; }
<div class="row"> <div class="col-md-4"> <span class="name">John Smith</span> <span class="info">10 friends</span> <img src="https://graph.facebook.com/102031900129645/picture?type=square&redirect=true&width=100&height=100" /> </div> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.