Html中div和table自动换行(中文和字符)

正常文字的换行(亚洲文字和非亚洲文字)

设置样式white-space:normal;

连续的英文字符和阿拉伯数字,使用word-wrap:break-word;或者word-break:break-all;实现强制断行


二、对于表格元素

    使用 table-layout:fixed;强制table的宽度,内层td,th采用word-break : break-all;或者word-wrap : break-word ;换行 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 `el-table` ,可以通过定义 `formatter` 函数来自定义表格的数据展示方式。如果想要根据字符来实现自动,可以通过使用 CSS 的 `word-break` 属性来实现。 具体实现步骤如下: 1. 在 `el-table-column` 定义 `formatter` 函数,该函数接收两个参数:`row` 表示该数据,`column` 表示该列属性。例如: ```html <el-table-column label="内容" prop="content"> <template slot-scope="scope"> {{ scope.row.content }} </template> <template slot="header"> <span>内容</span> </template> <template slot-scope="{ row }"> <div class="table-content">{{ row.content }}</div> </template> </el-table-column> ``` 2. 在 `formatter` 函数返回需要展示的 HTML 内容,可以在返回的内容使用 `<span>` 或 `<div>` 等标签来包裹需要字符,并设置 `word-break: break-all` 样式。例如: ```js <el-table-column label="内容" prop="content"> <template slot-scope="scope"> {{ scope.row.content }} </template> <template slot="header"> <span>内容</span> </template> <template slot-scope="{ row }"> <div class="table-content" v-html="breakWords(row.content)"></div> </template> </el-table-column> ... methods: { breakWords(str) { return '<span style="word-break: break-all;">' + str.replace(/(\r\n|\n|\r)/gm, '<br>') + '</span>'; } } ``` 在上面的例子,`breakWords` 方法将字符符替为 `<br>` 标签,同时将 `<span>` 标签包裹在字符串周围,并设置 `word-break: break-all` 样式来实现自动

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值