当前位置:网站首页>表格比手机屏幕宽时不压缩,可左右滚动,格子内容不换行
表格比手机屏幕宽时不压缩,可左右滚动,格子内容不换行
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>
边栏推荐
猜你喜欢
随机推荐
[Jiangsu University Self-Chemistry Association stm32F103c8t6] Notes [Entry 32 MCU and GPIO initialization parameter configuration]
【Qingdao Station】High-level application of SWAT model and modeling of areas without data, uncertainty analysis and climate change, improvement of land use surface pollution impact model and case analy
MATLAB怎么在图像中显示nii文件切片信息?
User password encryption using Bcrypt instead of MD5, SHA1 and SHA256
About map custom sorting of keys
QT连载4:基于QT和STM32H750的LORA试验平台(3)
TCP建立连接的过程
vs编译boost库脚本
QT连载1:readyRead()函数,数据分包不完整解决办法
Basic application of XMLBean
干货 | 什么是FOC?一文带你看BLDC电机驱动芯片及解决方案
survivor区对象何时进入老年代(深入理解jvm中表述不准确的地方)
边境的悍匪—机器学习实战:第十一章 训练深度神经网络
Self-augmented Unpaired Image Dehazing via Density and Depth Decomposition程序运行记录
this是什么(你不知道的JS)
Biome-BGC 生态系统模型与应用
QT连载3:基于QT和STM32H750的LORA试验平台(2)
Through the bit operations to convert the characters are case sensitive
Knowledge distillation method of target detection
边境的悍匪—机器学习实战:第十三章 使用TensorFlow加载和预处理数据









