限制表格里面的显示字数

本文介绍了如何在Bootstrap-Vue表格中处理文字显示,包括设置超出隐藏、显示省略号以及鼠标悬停时显示完整内容。具体方法涉及CSS样式如`overflow:hidden`, `text-overflow:ellipsis`, `white-space:nowrap`,以及使用`substring()`方法和`-webkit-line-clamp`等CSS3属性限制显示行数。" 106129718,5698975,使用Python与mac crontab实现自动签到,"['Python', 'macOS', '自动化', 'web自动化', '任务调度']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

关于bootstrap-vue表格里面的td文字样式处理

1、bootstrap-vue 的表格样式设置,文字超出隐藏,超出显示省略号,鼠标移入悬浮框显示内容。

2、文字限制输出两行,超出后隐藏

项目:

bootstrap-vue表格的处理:

代码如下:

<b-table striped hover bordered :items="infoList" :fields="theads" style="text-align:center;">

<template slot="action" slot-scope="row">

<b-button class="btn btn-info btn-sm" @click="getDetail(row.item)">查看

</b-button>

</template>

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、再表格里面做处理,给他设class,然后设置样式

<template slot="companyName" slot-scope="row">

<span class="tdWidth" :title="row.item.companyName"> {{row.item.companyName}}</span>

</template>

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

<template slot="contactAddress" slot-scope="row">

<span class="tdWidth" :title="row.item.contactAddress"> {{row.item.contactAddress}}</span>

</template>

</b-table>

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、样式设计:

.tdWidth {

width: 220px !important;

text-align:center;

display: block;

overflow: hidden;

white-space: nowrap;

text-overflow: ellipsis;

/* margin:0 auto; */

}

效果:超出省略号显示,鼠标移入出现文字悬浮框

###写法二

<b-table striped bordered hover :items="list" :fields="theads" show-empty empty-text="暂无可查询数据"

style=" table-layout: fixed;word-wrap:break-word;text-align:center;">

<template slot="carOfCompanys" slot-scope="row">

<span :title="row.value">{{(row.value && row.value.length> 50) ? row.value.substring(0, 62) + '...' :row.value}}</span>

</template>

<template slot="carNumbers" slot-scope="row">

<span :title="row.value">{{(row.value && row.value.length> 50) ? row.value.substring(0, 62) + '...' :row.value}}</span>

</template>

<template slot="remarks" slot-scope="row">

<span :title="row.value">{{(row.value && row.value.length> 50) ? row.value.substring(0, 62) + '...' :row.value}}</span>

</template>

、、、、、、、、、、

<template slot="index" slot-scope="row">{{row.index+1}}</template>

<template slot="carNumber" slot-scope="row">

<span :title="row.value">{{(row.value && row.value.length> 5) ? row.value.substring(0, 5) + '...' :

row.value}}</span>

</template>

<template slot="companyName" slot-scope="row">

<span :title="row.value">{{(row.value && row.value.length> 5) ? row.value.substring(0, 5) + '...' :

row.value}}</span>

</template>

 附上百度的相关内容:

百度:

CSS文本超出2行就隐藏并且显示省略号

今天做东西,遇到了这个问题,百度后总结得到了这个结果。

首先,要知道css的三条属性。

overflow:hidden; //超出的文本隐藏

text-overflow:ellipsis; //溢出用省略号显示

white-space:nowrap; //溢出不换行

这三个是css的基础属性,需要记得。

但是第三条属性,只能显示一行,不能用在这里,那么如果显示多行呢?

css3解决了这个问题,解决方法如下:

display:-webkit-box; //将对象作为弹性伸缩盒子模型显示。

-webkit-box-orient:vertical; //从上到下垂直排列子元素(设置伸缩盒子的子元素排列方式)

-webkit-line-clamp:2; //这个属性不是css的规范属性,需要组合上面两个属性,表示显示的行数。

最后的css样式如下:

overflow:hidden;

text-overflow:ellipsis;

display:-webkit-box;

-webkit-box-orient:vertical;

-webkit-line-clamp:2;

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>Examples</title>

<style type="text/css">

.demo{width:100px;}

</style>

</head>

<body>

<div class="demo" id="demo">怎么显示两行或三行文字,然后多出的部分省略号代替?</div>

<script>

// js无法直接通过class获取对象,必须自己写一个方法,这样效率会非常低,原生js里最好用id获取,

// 直接用id获取domo对象

var oBox=document.getElementById('demo');

// slice() 方法可从已有的数组中返回选定的元素。

// 您可使用负值从数组的尾部选取元素。

// 如果 end 未被规定,那么 slice() 方法会选取从 start 到数组结尾的所有元素。

// 此处需要根据需求自行修改slice()的值,以达到要显示的内容

var demoHtml = oBox.innerHTML.slice(0,10)+'...';

// 填充至指定位置

oBox.innerHTML = demoHtml;

</script>

</body>

</html>

2、限制宽度,最多显示三行,其余超出省略号显示,文字悬浮框

 

3、第二种处理方法 substring()属性

定义和用法

substring() 方法用于提取字符串中介于两个指定下标之间的字符。

substring() 方法返回的子串包括 开始 处的字符,但不包括 结束 处的字符。

语法

string.substring(from, to)

 

参数

描述

from

必需。一个非负的整数,规定要提取的子串的第一个字符在 string Object 中的位置。

to

可选。一个非负的整数,比要提取的子串的最后一个字符在 string Object 中的位置多 1。 如果省略该参数,那么返回的子串会一直到字符串的结尾。

为了保持界面的美观,在使用bootstrap-vue框架的时候,需要在他的表格样式那里添加table-layout: fixed;word-wrap:break-word;text-align:center;这些属性,既防止表格/层撑破又防止单词断裂

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值