效果圖:
實現原理很簡單,使用flex佈局,中間的填充使用border屬性,看似是很多點,其實是一個盒子的border。
並且自動適應填充。
html代碼:
<div class="text-container">
<p class="name">交通出行</p>
<p class="fill"></p>
<p class="cost">3024元</p>
</div>
css代碼:
.text-container{
display: flex;
justify-content: space-between;
align-items: center;
}
.text-container p{
font-size: 22px;
margin-bottom: 5px;
white-space: nowrap;
}
.cost{
text-align: right;
}
.fill{
width: 100%;
height: 1px;
border-top: dotted #000 2px; /* 可設置大小,查屬性參數dotted可換其他樣式 */
margin: 0 10px; /* 用來控制文字與填充線的間隔大小 */
}