• uni-app解决表格uni-table样式问题


    一、如何让表格文字只显示一行,超出部分用省略号表示

    步骤 :
    • 给table设置table-layout:fixed; 列宽由表格宽度和列宽度设定。(默认是由单元格内容设定)
    • 让表格元素继承父元素宽度固定table-layout: inherit;
    • overflow: hidden;超过部分隐藏,text-overflow: ellipsis; 超出部分用省略号表示 ,white-space: nowrap; 不换行。
    • 给表格设置宽度:width: 360rpx; box-sizing: content-box;(计算过程不包括边框)
    代码: 
    1. .uni-table {
    2. table-layout: fixed;
    3. // height: 15.5rem;
    4. overflow: hidden;
    5. text-overflow: ellipsis; //省略号表示
    6. white-space: nowrap; //不换行
    7. .uni-table-td {
    8. table-layout: inherit;
    9. overflow: hidden;
    10. text-overflow: ellipsis; //省略号表示
    11. white-space: nowrap; //不换行
    12. }
    13. .uni-table-th {
    14. width: 360rpx; // !important
    15. box-sizing: content-box;
    16. }
    17. }

    二、如何固定表的第一列 

    步骤: 

     在第一列uni-th中加上类名first,随后设置固定位置,个人尝试过使用position: sticky;在App中并没有生效。此外,element-plus导入到uni-app项目运行到真机中也会报错,因为样式冲突和导入方式等问题,无法使用,后续找到解决方案会更新,所以没有使用el-table来实现。

    代码: 
    1. .first {
    2. width: 120rpx;
    3. position: fixed;
    4. background-color: #FFFAF2;
    5. z-index: 10;
    6. }

     三、如何利用弹出层实现弹框效果

    步骤: 
    代码: 
    1. <uni-popup ref="popup" :mask-click="false">
    2. <uni-table ref="table" border stripe>
    3. <uni-tr>
    4. <uni-th width="90" align="center">123uni-th>
    5. <uni-th width="200" align="center">123uni-th>
    6. uni-tr>
    7. <uni-tr>
    8. <uni-th width="90" align="center">234uni-th>
    9. <uni-th width="200" align="center">234uni-th>
    10. uni-tr>
    11. <uni-tr>
    12. <uni-th width="90" align="center">345uni-th>
    13. <uni-th width="200" align="center">345uni-th>
    14. uni-tr>
    15. uni-table>
    16. <button @click="close">关闭button>
    17. uni-popup>

    四、总数据条数和分页索引如何显示 

    步骤: 

            通过检查页面效果来找到对应隐藏的内容,在进行样式设置,如果没有生效,考虑使用!important。

    代码: 
    1. .is-phone-hide {
    2. display: block;
    3. }
    4. .uni-pagination {
    5. font-size: 24rpx;
    6. .uni-pagination__num-tag {
    7. margin: 0 20rpx;
    8. }
    9. .uni-pagination__num {
    10. display: inline-block;
    11. }
    12. }

    效果展示:

    CSS全部代码: 
    1. .uni-container {
    2. margin-top: 60rpx;
    3. .example-demonstration {
    4. height: 590rpx;
    5. }
    6. .uni-table {
    7. table-layout: fixed;
    8. // height: 15.5rem;
    9. overflow: hidden;
    10. text-overflow: ellipsis;
    11. white-space: nowrap;
    12. .uni-table-td {
    13. table-layout: inherit;
    14. overflow: hidden;
    15. text-overflow: ellipsis; //省略号表示
    16. white-space: nowrap; //不换行
    17. }
    18. .uni-table-th {
    19. width: 360rpx; // !important
    20. box-sizing: content-box;
    21. }
    22. .taxId {
    23. padding-left: 60rpx;
    24. width: 240rpx;
    25. }
    26. uni-view {
    27. overflow: hidden;
    28. width: 100%;
    29. text-overflow: ellipsis; //省略号表示
    30. white-space: nowrap; //不换行
    31. }
    32. .first {
    33. width: 120rpx;
    34. // display: flex;
    35. position: fixed;
    36. background-color: #FFFAF2;
    37. z-index: 10;
    38. }
    39. .fixed-th {
    40. width: 77rpx;
    41. }
    42. }
    43. .is-phone-hide {
    44. display: block;
    45. }
    46. .uni-pagination {
    47. font-size: 24rpx;
    48. .uni-pagination__num-tag {
    49. margin: 0 20rpx;
    50. }
    51. .uni-pagination__num {
    52. display: inline-block;
    53. }
    54. }
    55. }

     以上内容参考:CSS table-layout 属性 | 菜鸟教程uni-app官网

  • 相关阅读:
    # 数值计算:三角形积分
    车载电池充电器亚马逊要求的UL2089测试项目
    java计算机毕业设计弹幕视频网站源码+系统+lw文档+mysql数据库+部署
    树莓派+墨水屏 = DIY一个超慢速电影播放器
    Java复习知识点基础篇三
    高危漏洞分析|CVE-2022-42920 Apache Commons BCEL 越界写漏洞
    带您识别RJ45网口连接器/网口插座口的LED灯的平脚/斜脚,带弹/不带弹细节区分
    清华“洗衣机系”学霸,如何在 GitHub 拿下 50000+Star?
    IDEA报错:No valid Maven installation found
    Maven配置私有仓库
  • 原文地址:https://blog.csdn.net/GLimerence/article/details/139283076