IE8 中text-overflow:ellipsis 与text-align:right组合样式BUG

本文介绍如何使用CSS属性text-overflow实现文本溢出时显示省略号,并解决在IE8浏览器中出现的问题。当结合text-align:right样式时,省略号可能会被覆盖,通过添加text-indent可以有效避免该问题。

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


text-overflow:ellipsis 作用是显示省略符号来代表被修剪的文本

<span style="font-family: Verdana, Arial, 宋体; background-color: rgb(239, 239, 239);">IE8中不添加 text-align :right 样式是没有问题的</span>

例:

<div style="width:150px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;word-wrap:normal;">显示省略符号来代表被修剪的文本</div>

结果是这样的


加上 text-align:right;之后,变成这样了

省略号完全被覆盖了。


此时,需要添加 

     text-indent:10px;
之后就能正常显示了



<template> <el-card class="mb-[10px]"> <template #header> 待办 </template> <el-empty v-if="todos.length === 0" description="暂无待办事项" /> <div v-for="todo in todos" :key="todo.id" class="item" v-else> <div class="title-box"> <div class="title">{{ todo.title }}</div> <el-tag type="primary" v-if="todo.status === 1">未开始</el-tag> <el-tag type="success" v-else-if="todo.status === 2">已完成</el-tag> <el-tag type="warning" v-else-if="todo.status === 3">进行中</el-tag> <el-tag type="danger" v-else>已过期</el-tag> </div> <div class="desc">{{ todo.description }}</div> <div class="expire">截止日期:{{ todo.createdAt }}</div> </div> </el-card> </template> <script setup> import { formatDate } from '@/utils/formatTime' // 待办事项数据 const todos = ref([ { id: 1, title: '完成季度财务报告', description: '整理所有部门的财务数据并生成季度报告', status: 1, dueDate: new Date(Date.now() + 86400000 * 2), // 2天后 createdAt: '2025-12-23' }, { id: 2, title: '修复登录页面BUG', description: '用户反馈登录页面验证码无法显示的问题', status: 2, dueDate: new Date(Date.now() + 86400000), // 1天后 createdAt: '2025-12-23' }, { id: 3, title: '更新产品文档', description: '根据最新版本更新用户手册和技术文档', status: 1, dueDate: new Date(Date.now() + 86400000 * 5), createdAt: '2025-12-23' }, { id: 4, title: '准备团队建设活动', description: '策划下个月的团队建设活动方案', status: 4, dueDate: new Date(Date.now() - 86400000), createdAt: '2025-12-23' } ]) </script> <style lang="scss" scoped> .item { width: 100%; .title-box { width: 100%; display: flex; align-items: center; } .title { width: calc(100% - 100px); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } } </style> 样式优化
最新发布
07-15
<template> <div> <el-dialog title="设备导入" :visible.sync="dialogVisible" width="600px" custom-class="ota-dialog" :close-on-click-modal="false" > <div class="dialog-content"> <div class="action-section"> <div class="upload-section"> <el-upload action="#" :auto-upload="false" :before-upload="beforeUpload" :on-change="handleFileChange" :limit="1" :on-exceed="handleExceed" :file-list="fileList" drag > <i class="el-icon-upload"></i> <div class="el-upload__text"> <div>点击或拖拽文件到此处上传</div> <div class="el-upload__tip">支持.xlsx、.xls格式文件</div> </div> </el-upload> <div v-if="fileList.length" class="file-card"> <div class="file-info"> <i class="el-icon-document"></i> <div class="file-details"> <div class="file-name">{{ fileList[0].name }}</div> <div class="file-size">{{ formatFileSize(fileList[0].size) }}</div> <div v-if="firstRowString" class="file-data"> <el-tooltip effect="dark" :content="firstRowString" placement="top"> <span>首行数据: {{ truncateString(firstRowString) }}</span> </el-tooltip> </div> </div> </div> <div class="file-actions"> <i v-if="loading" class="el-icon-loading"></i> <el-button v-else type="danger" icon="el-icon-delete" circle @click="clearFile" ></el-button> </div> </div> </div> </div> </div> <div slot="footer" class="dialog-footer"> <el-button @click="dialogVisible = false">取 消</el-button> <el-button type="primary" @click="handleConfirm" :disabled="!fileList.length || loading" > {{ loading ? '处理中...' : '确 定' }} </el-button> </div> </el-dialog> </div> </template> <script> import * as XLSX from 'xlsx'; export default { data() { return { dialogVisible: false, fileList: [], firstRowString: '', loading: false }; }, methods: { init() { this.dialogVisible = true; this.fileList = []; this.firstRowString = ''; }, beforeUpload(file) { const isValidType = [ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel' ].includes(file.type); if (!isValidType) { this.$message.error('请上传Excel格式的文件 (.xlsx 或 .xls)'); } return isValidType; }, // 处理文件选择变化 handleFileChange(file) { if (!file) return; const validTypes = [ 'application/vnd.ms-excel', // .xls 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' // .xlsx ]; if (!validTypes.includes(file.raw.type)) { this.$message.error('请上传Excel格式的文件 (.xlsx 或 .xls)'); this.clearFile(); return; } this.fileList = [file]; this.readExcelFirstRow(file.raw); }, // 读取Excel文件第一行 readExcelFirstRow(file) { this.loading = true; const reader = new FileReader(); reader.onload = (e) => { try { const data = new Uint8Array(e.target.result); const workbook = XLSX.read(data, { type: 'array' }); // 获取第一个工作表 const firstSheetName = workbook.SheetNames[0]; const worksheet = workbook.Sheets[firstSheetName]; // 获取第一行数据 const range = XLSX.utils.decode_range(worksheet['!ref']); const firstRow = []; // 遍历第一行的所有列 for (let col = range.s.c; col <= range.e.c; col++) { const cellAddress = XLSX.utils.encode_cell({ r: 0, c: col }); const cell = worksheet[cellAddress]; firstRow.push(cell ? cell.v : ''); } // 用分号拼接第一行数据 this.firstRowString = firstRow.join(';'); this.$message.success('Excel文件解析成功'); } catch (error) { console.error('Excel解析错误:', error); this.$message.error('Excel文件解析失败,请检查文件格式'); this.firstRowString = ''; } finally { this.loading = false; } }; reader.onerror = () => { this.$message.error('文件读取失败'); this.loading = false; }; reader.readAsArrayBuffer(file); }, // 处理确认操作 handleConfirm() { if (!this.firstRowString) { this.$message.warning('未解析到有效数据'); return; } this.$message.success(`已获取首行数据: ${this.firstRowString}`); // 这里可以添加将数据发送到服务器的逻辑 // this.otaBatchUpgradeConfirm(this.firstRowString); // 关闭对话框 this.dialogVisible = false; }, // 清空文件 clearFile() { this.fileList = []; this.firstRowString = ''; }, handleExceed() { this.$message.warning('每次只能上传一个文件'); }, formatFileSize(size) { if (size < 1024) return size + ' B'; if (size < 1024 * 1024) return (size / 1024).toFixed(1) + ' KB'; return (size / (1024 * 1024)).toFixed(1) + ' MB'; }, // 截断长字符串 truncateString(str, maxLength = 30) { if (str.length <= maxLength) return str; return str.substring(0, maxLength) + '...'; } } }; </script> <style scoped> .action-section { display: flex; flex-direction: column; gap: 20px; } .upload-section { position: relative; display: flex; justify-content: center; } .file-card { margin-top: 15px; padding: 15px; border-radius: 8px; background-color: #f5f7fa; display: flex; align-items: center; justify-content: space-between; border: 1px solid #ebeef5; } .file-info { display: flex; align-items: center; gap: 12px; flex: 1; } .file-info i { font-size: 28px; color: #409EFF; } .file-details { line-height: 1.5; flex: 1; } .file-name { font-weight: 500; max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .file-size { font-size: 12px; color: #909399; } .file-data { font-size: 12px; color: #67C23A; margin-top: 5px; max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .file-actions { margin-left: 10px; } .dialog-footer { display: flex; justify-content: flex-end; padding-top: 15px; border-top: 1px solid #ebeef5; } .has-file >>> .el-upload-dragger { border: 1px dashed #67C23A; background-color: rgba(103, 194, 58, 0.05); } .el-icon-loading { font-size: 20px; color: #409EFF; margin-right: 10px; } </style> 上传文件后布局混乱
07-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值