当前位置:网站首页>表格比手机屏幕宽时不压缩,可左右滚动,格子内容不换行
表格比手机屏幕宽时不压缩,可左右滚动,格子内容不换行
2022-07-30 05:45:00 【Nashomon】
Bootstrap响应式表格比较宽时,为适应手机屏幕宽度,会自动对各列进行压缩,内容分多行显示。但像姓名分几行显示效果不好。我们希望表格显示不下时,不改变列宽度,而是出现滚动杆,保持表格原来的外观。
可通过设置white-space: nowrap属性来实现。
CSS 样式代码:
用于禁止格子内换行。
.cell_nowrap {
white-space: nowrap;
}
HTML代码:
<div class="table-responsive">
<table class="table table-bordered cell_nowrap" >
<!-- 表头 -->
<thead>
<tr><th>年级</th><th>学生</th><th>题目</th></tr>
</thead>
<tbody>
<!-- 表格内容 -->
<tr><td>2019</td><td>张小三</td><td>文字不换行在手机上的显示,显示不下时自动出现滚动条</td></tr>
<tr><td>2019</td><td>赵小四</td><td>文字不换行在手机上的显示,显示不下时自动出现滚动条</td></tr>
<tr><td>2019</td><td>王小五</td><td>不会出现姓名栏变窄竖排</td></tr>
</tbody>
</table>
</div>
这里用的是Bootstrap4,类table-responsive、table使表格成为响应式表格,会根据屏幕大小自适应显示。
完整代码如下,可在服务器上运行显示效果。
<html>
<head>
<meta charset="UTF-8" >
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>表格单元内容不换行</title>
<!-- Bootstrap4 CSS -->
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<!-- 自定义样式 -->
<style> .cell_nowrap {
white-space: nowrap; } </style>
</head>
<body>
<div class="container">
<div class="table-responsive">
<table class="table table-bordered cell_nowrap" >
<!-- 表头 -->
<thead>
<tr><th>年级</th><th>学生</th><th>注释</th></tr>
</thead>
<tbody>
<!-- 表格内容 -->
<tr><td>2019</td><td>张小三</td><td>文字不换行在手机上的显示,显示不下时自动出现滚动条</td></tr>
<tr><td>2019</td><td>赵小四</td><td>文字不换行在手机上的显示,显示不下时自动出现滚动条</td></tr>
<tr><td>2019</td><td>王小五</td><td>不会出现姓名栏变窄竖排</td></tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
边栏推荐
- 一文盘点五款 BLDC 风机参考方案,建议先马
- 【正点原子】sys.c、sys.h位带操作的简单应用
- 新导则下 防洪评价报告编制方法及洪水建模(HEC-RAS)
- Antd 树拖拽一些细节,官网没有,摸坑篇
- QT连载4:基于QT和STM32H750的LORA试验平台(3)
- Self-augmented Unpaired Image Dehazing via Density and Depth Decomposition program running record
- 干货:线上下单应知应会,快来了解下
- Three working modes of CPU: real mode, protected mode, long mode
- ipconfig命令指南
- 重磅揭晓!第十四届深创赛福田预选赛区暨华秋第八届硬创大赛华南分赛区晋
猜你喜欢
随机推荐
迪文串口屏幕制作(连载一)=====准备工作
Rsync realizes folder or data synchronization between Win systems
Generalized Focal Loss 论文阅读笔记
Application of remote sensing, GIS and GPS technology in hydrology, meteorology, disaster, ecology, environment and health
XMLBean的基础运用
逻辑右移和算术右移区别
influxDB运维记录
闭包(你不知道的JS)
ipconfig命令指南
边境的悍匪—机器学习实战:第八章 降维
Sklearn : train_test_split()函数的用法
TCP建立连接的过程
[Jiangsu University Automation Association stm32F103c8t6] Notes [Initial 32 MCU and EXTI External Interrupt Initialization Parameter Configuration]
昆仑通态屏幕制作(连载4)---基础篇(图形设定与显示,按钮灯)
干货:线上下单应知应会,快来了解下
TCP为什么要三次握手,握手过程中丢包会怎么样?
联影医疗二面
干货 | 什么是FOC?一文带你看BLDC电机驱动芯片及解决方案
R-GIS: 如何用R语言实现GIS地理空间分析及模型预测
R - GIS: how to use R language implementation of GIS geospatial analysis and model prediction








