日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

解決多個el-checkbox內容折行對不齊問題(可以限制每行展示的個數)

作者:migexiaoliang 更新時間: 2022-08-15 編程語言

項目場景:

有時候使用element的el-checkbox-group多個el-checkbox內容折行后不對齊,如下圖所示:

在這里插入圖片描述


解決方案:

可以用樣式來調整(可以限制每行展示的個數)

實現代碼:

<el-form-item label="地域設置:" prop="regionIdList" class="region-list-style">
 <el-checkbox-group v-model="userForm.regionIdList">
    <el-checkbox
      :label="item.name"
      v-for="item in azonesListData[1]"
      :key="item.id"
      :disabled="item.status === 1"
      class="region-list-item"
      :title="item.name">
      <span>
        {{ item.name.length > 10 ? item.name.substring(0, 10) + '...' : item.name }}
      </span>
    </el-checkbox>
  </el-checkbox-group>
</el-form-item>

css代碼:

<style scoped>
/* 用來對齊 */
.region-list-style /deep/ .el-checkbox + .el-checkbox {
  margin-left: 0px;
}
.region-list-style /deep/ .el-checkbox {
  margin-right: 25px;
}
/* 用來調整每一項的寬度 */
.region-list-item {
  width: 150px;
  white-space: nowrap;
  /* text-overflow: ellipsis; */
  overflow: hidden;
}
</style>

代碼解釋:

  1. 最多展示10個字符,多了被截斷
{{ item.name.length > 10 ? item.name.substring(0, 10) + '...' : item.name }}
  1. 鼠標懸停后展示全部
:title="item.name"

最終效果圖:

在這里插入圖片描述

原文鏈接:https://blog.csdn.net/migexiaoliang/article/details/125509376

欄目分類
最近更新