ttentau1

纯前端,如何让表格在多种分辨率下,自适应宽度,表头不换行?

  •  
  •   ttentau1 · Jan 5, 2019 · 3904 views
    This topic created in 2715 days ago, the information mentioned may be changed or developed.

    遇到的问题是:

    1. 表格在低分辨率(主要是 1280 和 1360 这两个)下,表头的内容会换行,会导致非常的整体看起来非常的难看。
    2. 表格行数过多,会导致所有行的宽度变窄。宽度变窄后,表头的内容也会换行。会导致非常的整体看起来非常的难看。 注:数据是 php 渲染,后端不提供接口。所以 ElementUI 这种、layui 这种用不了。前端唯一能做的就是写 css 调样式、js 操作 dom。 请问各位大佬有什么解决方法吗?
    5 replies    2019-01-06 00:02:00 +08:00
    woscaizi
        1
    woscaizi  
       Jan 5, 2019
    字体大小通过设置 rem 缩放下。
    learnshare
        2
    learnshare  
       Jan 5, 2019
    设置每一列的最小宽度,列多了允许横向滚动
    old9
        3
    old9  
       Jan 5, 2019
    不换行就会导致整个表格横向超过页面范围,如果你要的就是这个效果,那表头 th{white-space: nowrap} 应该就可以了。

    另外一个方案是动态缩小字体,要复杂一些,可以查查 fluid typography 关键字。
    ttentau1
        4
    ttentau1  
    OP
       Jan 5, 2019
    感谢大家回复,目前已经找到解决方法了,引入 bootstrap-table 这个库就行了
    rrfeng
        5
    rrfeng  
       Jan 6, 2019
    看到楼主的解决方案为什么有种好笑的感觉。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   957 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 102ms · UTC 22:45 · PVG 06:45 · LAX 15:45 · JFK 18:45
    ♥ Do have faith in what you're doing.