<span>中显示文字超出宽度如何自动隐藏

本文介绍如何使用CSS属性如overflow、display等来实现文本溢出时的自动隐藏效果,适用于块级元素。

<span>中显示文字超出宽度如何自动隐藏

匿名  |  浏览 15444 次   问题未开放回答  |举报
推荐于2016-09-13 23:28:54 最佳答案
首先,溢出隐藏就先想到代码overflow: hidden;

其次,溢出隐藏必须设置元素的宽或者高,因为你不确定宽或者高,也就不知道它超出什么范围才隐藏;

最后,因为只有块级元素才能设置宽和高,而span是行内元素,要转换成块级元素用代码display:block。
超级扫帚 | 2016-9-9 10:00
复制有意思吗 回复

光环国际  | IT·互联网经理人培训中国第一...

主营:PMP培训、软考培训、企业咨询、IT培训

给TA留言

其他回答

楼上正解。
首先,溢出隐藏就先想到代码overflow: hidden
其次,溢出隐藏必须设置元素的宽或者高,你不确定宽或者高它怎么知道超出什么范围才隐藏呢
最后,因为只有块级元素才能设置宽和高,而span是行内元素,要转换成块级元素用代码display:block
 本回答被网友采纳
鰟鮍鱼    |  发布于2013-01-15 21:16
举报|  评论(1) 
18  10
Soimissu_plum | 2013-4-1 10:59
回答的好专业,厉害! 回复
<span style="width:100px; height:100px; display:block;overflow: hidden;"></span>
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>Internal Engineering Change Notice (ECN) Request - View</title> <style> .container { margin: auto; border: 1px solid #ccc; padding: 20px 20px 0px 20px; font-family: Arial, sans-serif; } .container h2 { text-align: center; } .header { display: flex; align-items: center; margin-bottom: 20px; } .header-info { font-size: 14px; } .form-group { display: flex; margin-bottom: 15px; } .container label { display: inline-block; width: 300px; font-weight: bold; } input[type="text"], input[type="date"], input[type="time"], textarea { width: 200px; padding: 5px; } .checkbox-group { display: flex; align-items: center; } .checkbox-group label { margin-right: 10px; font-weight: normal; margin-right: 5px; /* 控制每个复选框之间的间距 */ width: 60px; } .section { margin-top: 20px; padding-top: 10px; border-top: 1px solid #ccc; } .container .footer { margin-top: 30px; display: flex; justify-content: space-between; font-size: 12px; color: #555; } .row { display: flex; width: 100%; gap: 10px; } .col { display: flex; align-items: center; white-space: nowrap; } .col label { white-space: nowrap; margin-right: 1px; font-weight: bold; } .approval-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; } .approval-table th, .approval-table td { padding: 10px; border: 1px solid #ccc; vertical-align: top; } .approval-table th { background-color: #f5f5f5; text-align: left; } .center-text { display: flex; justify-content: center; align-items: center; } label span { font-weight: normal; text-decoration: underline; } </style> </head> <body> <div> <div class="center-text"> <div style="width:980px;text-align:left;"> <div class="container" layoutH="56"> <input name="id" id="id" type="hidden" value="{$list.id}" /> <input name="navTabId" id="navTabId" type="hidden" value="{$navTabId}" /> <div class="header" style="display: flex; justify-content: space-between; align-items: center;"> <img src="__PUBLIC__/Images/logo.gif" alt="Logo"> <strong>Ref. No:{$list.ref_no} </strong> </div> <div class="header" style="justify-content: center;"> <h2 style="font-size: 32px;">Internal Engineering Change Notice (ECN) Requests</h2> </div> <div class="form-group"> <div class="col"> <label>Requested by #: <span>{$list.requested_by}</span></label> </div> <div class="col checkbox-group" style="justify-content: flex-start; padding-left: 5px;"> <label> <input type="radio" name="requested_department" <if condition="$list.requested_department eq 'ME'">checked</if> /> <label for="ME" style="margin-left: 1px;">ME</label> </label> <label> <input type="radio" name="requested_department" <if condition="$list.requested_department eq 'PE'">checked</if> /> <label for="PE" style="margin-left: 1px;">PE</label> </label> <label> <input type="radio" name="requested_department" <if condition="$list.requested_department eq 'QA'">checked</if> /> <label for="QA" style="margin-left: 1px;">QA</label> </label> <label> <input type="radio" name="requested_department" <if condition="$list.requested_department eq 'PMC'">checked</if> /> <label for="PMC" style="margin-left: 1px;">PMC</label> </label> </div> <div class="col" style="margin-left: 200px;"> <label style="width: 100px;">Ext. no: <span>{$list.ext_no}</span></label> </div> </div> <div style="margin-top: 15px;"> <label>Date (MM/DD/YYYY):<span>{$list.request_date|date='m/d/Y',###}</span></label> </div> <div class="section"> <h4 style="font-size: 20px;">Part A: General Project and Change Information (Fill by Requestor):</h4> <div style="margin-bottom: 15px;margin-top: 10px;"> <label>PNG Part No:<span>{$list.png_part_no}</span></label> <label style="margin-left: 10px;">Customer:<span>{$list.customer}</span></label> <label style="margin-left: 10px;">Customer code:<span>{$list.customer_code}</span></label> </div> <div class="form-group"> <label>Purpose / Reason of ECN:<span>{$list.purpose_reason}</span></label> </div> <div class="form-group"> <label style="width: 400px;margin-top: 5px;">Change area: Manufacturing Instruction(M.I.) #:</label> <div class="col checkbox-group" style="justify-content: flex-start; padding-left: 5px;"> <label><input type="radio" <if condition="$list.change_area_manufacturing eq 'YES'">checked</if> /> YES</label> <text>/</text> <label><input type="radio" <if condition="$list.change_area_manufacturing eq 'NO'">checked</if> /> NO</label> </div> <label style="margin-left: 100px;width: 100px;">Tooling#:</label> <div class="checkbox-group" style="justify-content: flex-start; padding-left: 5px;"> <label><input type="radio" <if condition="$list.tooling eq 'YES'">checked</if> /> YES</label> <text>/</text> <label><input type="radio" <if condition="$list.tooling eq 'NO'">checked</if> /> NO</label> </div> </div> </div> <div class="section"> <h4 style="font-size: 20px;">Part B: Change Description (Fill by Requestor):</h4> <div class="header" style="justify-content: center;"> <h2>ECN Change Details (add attachment if needed)</h2> </div> <div class="form-group"> <label style="width: 100px;">From:</label> <div>{$list.change_from}</div> </div> <div class="form-group"> <label style="width: 100px;">To:</label> <div>{$list.change_to}</div> </div> <label style="white-space: nowrap;">Involve Work Order in Production #:</label> <div class="form-group"> <label style="width: 80px;"><input type="radio" <if condition="$list.involve_work_order eq 'YES'">checked</if> /> YES -</label> <label style="width: 400px;"><input type="radio" <if condition="$list.request_change_date_option eq 'YES'">checked</if> />Request Change Date: <span>{$list.request_change_date|date='m/d/Y',###}</span>(MM/DD/YYYY) </label> <label style="margin-left: 50px;">Time: <span style="font-weight: normal;">{$list.request_change_time}(HH:MM)</span> </label> </div> <div class="form-group" style="margin-left: 80px;"> <label style="white-space: nowrap;width: 300px;"><input type="radio" <if condition="$list.implement_after_option eq 'YES'">checked</if> />Implement after * W/O / DC/Process <span>{$list.implement_after}</span></label> </div> <div class="form-group" style="margin-left: 80px;"> <label style="white-space: nowrap;width: 250px;"><input type="radio" <if condition="$list.assigned_by_pmc eq 'YES'">checked</if> />Assigned by PMC (Go to PartC)</label> </div> <div class="form-group"> <label style="white-space: nowrap;"><input type="radio" <if condition="$list.involve_work_order eq 'NO'">checked</if> />NO(Change date schedule byPE)</label> </div> <div class="form-group"> <label style="white-space: nowrap;">M.I & Tooling disposition by #:</label> <div class="checkbox-group" style="margin-left: 50px;"> <label style="width: 150px;"><input type="radio" <if condition="$list.mi_tooling_disposition_by eq 'New Part number'">checked</if> /> New Part number</label> <label style="width: 150px;"><input type="radio" <if condition="$list.mi_tooling_disposition_by eq 'Up-version'">checked</if> /> Up-version</label> <label style="width: 150px;"><input type="radio" <if condition="$list.mi_tooling_disposition_by eq 'Amendment'">checked</if> /> Amendment</label> </div> </div> </div> <div class="section"> <h4 style="font-size: 20px;">Part C: Running change schedule: (Fill by PMC)</h4> <div class="form-group" style="margin-top: 20px;"> <label style="width:400px;">Assign Change Date: <span>{$list.assign_change_date|date='m/d/Y',###}(MM/DD/YYYY)</span> </label> <label style="margin-left: 50px;">Time: <span>{$list.assign_change_time}(HH:MM)</span> </label> </div> </div> <div class="section"> <h4 style="font-size: 20px;">Part D: Approval</h4> <table class="approval-table"> <tr> <td>Department Manager of requestor: <span>{$list.department_manager_signature}</span></td> <td>M.E <br/><span>{$list.me_signature}</span></td> <td>P.E <br/><span>{$list.pe_signature}</span></td> <td>PMC <br/><span>{$list.pmc_signature}</span></td> <td>QA <br/><span>{$list.qa_signature}</span></td> </tr> <tr> <td>Date (MM/DD/YYYY):<span>{$list.department_manager_date|date='m/d/Y',###}</span></td> <td>Date (MM/DD/YYYY):<span>{$list.me_date|date='m/d/Y',###}</span></td> <td>Date (MM/DD/YYYY):<span>{$list.pe_date|date='m/d/Y',###}</span></td> <td>Date (MM/DD/YYYY):<span>{$list.pmc_date|date='m/d/Y',###}</span></td> <td>Date (MM/DD/YYYY):<span>{$list.qa_date|date='m/d/Y',###}</span></td> </tr> </table> </div> <div class="footer"> <div>Form No. PEF-005</div> <div>Version: A/2</div> <div>Effective Date: 09/09/2024</div> </div> </div> </div> </div> </div> </body> </html> <script language="javascript" type="text/javascript" src="__PUBLIC__/dwz/js/autosize.min.js"></script> <SCRIPT LANGUAGE="JavaScript"> $(document).ready(function () { $("#printbt").click(function(){ $("div#myPrintArea").printArea(); }); // 禁止所有 radio 按钮被点击修改 $('input[type="radio"]').each(function () { $(this).data('waschecked', $(this).is(':checked')); // 保存原始状态 $(this).on('click', function (e) { e.preventDefault(); // 阻止默认行为 return false; }); }); }); </script> part d的table表格部分超出了980px的宽度限制是为什么
最新发布
07-27
<template> <div class="taskBox"> <div v-for="(item,index) in list" class="itemList"> <div class="top">【{{ item.userTypeName }}】{{ item.taskName }}</div> <div class="centre"> <p> <span><img :src="icon1"/></span> <span>起止时间</span> <span>:{{ item.startTime }}~{{ item.endTime }}</span> </p> <p> <span> <img :src="icon2"/></span> <span>适用范围</span> <span>:{{ item.useRange }}</span> </p> <p> <span> <img :src="icon3"/></span> <span>说明</span> <span>:{{ item.taskRemark }}</span> </p> </div> <div class="bottom"> <div class="statusBox statusBox1" v-if="item.status=='正在进行'">{{ item.status }}</div> <div class="statusBox statusBox2" v-else>{{ item.status }}</div> <div class="FillingBox" @click="goFillingFun(item.id)">快速填报&nbsp></div> </div> </div> </div> </template> <script setup> import {useRoute, useRouter} from 'vue-router' import {post} from "@/frame/request/http"; import {ref} from "vue"; import icon1 from '../../assets/image/taskFillingIcon1.png' import icon2 from '../../assets/image/taskFillingIcon2.png' import icon3 from '../../assets/image/taskFillingIcon3.png' let router = useRouter() function goFillingFun(id) { router.push('/taskFilling?id=' + id) } let list = ref([]) const search = ref({ pageNum: 1, pageSize: 2, total: 0, }); const currentDate = new Date(); // 状态判断函数 function getTaskStatus(startDateStr, endDateStr, currentDate) { // 将字符串转换为日期对象 const startDate = new Date(startDateStr); const endDate = new Date(endDateStr); // 清除时间部分,只比较日期 startDate.setHours(0, 0, 0, 0); endDate.setHours(0, 0, 0, 0); const current = new Date(currentDate); current.setHours(0, 0, 0, 0); if (current < startDate) { return "未开始"; } else if (current > endDate) { return "已过期"; } else { return "正在进行"; } } function getList() { post('/system/module/task/set/teacherPageList', search.value).then(res => { list.value = res.list list.value.forEach(task => { const status = getTaskStatus(task.startTime, task.endTime, currentDate); task.status = status; }); console.log(list.value, 78) }) } getList() </script> <style scoped lang="less"> .taskBox { height: 235px; width: 100%; display: flex; flex-wrap: wrap; gap: 24px; } .itemList { flex: 1; background-color: white; border-radius: 10px; padding: 24px; box-sizing: border-box; display: flex; flex-direction: column; justify-content: space-between; .top { font-size: 18px; font-weight: bolder; } .centre { height: 114px; width: 100%; background-color: #f7f9fc; padding: 20px; display: flex; flex-direction: column; justify-content: space-between; box-sizing: border-box; border-radius: 5px; p { display: flex; //flex-direction: column; //justify-content: center; span { &:nth-child(1) { display: flex; justify-content: center; align-items: center; img { width: 18px; height: 18px; margin-right: 5px; } } &:nth-child(2) { font-size: 14px; color: #666666; width: 72px; display: inline-block; text-align: justify; text-align-last: justify; } &:nth-child(3) { font-size: 14px; color: #333333; font-weight: 500; } } } } .bottom { display: flex; justify-content: space-between; .statusBox { width: 100px; height: 24px; line-height: 24px; display: flex; justify-content: center; color: white; border-radius: 5px; } .statusBox1 { background-image: linear-gradient(to right, #487ff7, #ffffff); } .statusBox2 { background-image: linear-gradient(to right, #cecece, #ffffff); } .FillingBox { color: #427bf7; cursor: pointer; } } } </style>优化一下,把适用范围和说明改成一行显示超出显示省略号
07-18
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值