CSS:純css樣式實現左右兩側文字中間填充點或線(仿賬單報表樣式),自適應

效果圖:
在這裏插入圖片描述
實現原理很簡單,使用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; /* 用來控制文字與填充線的間隔大小 */
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章