Table里td中的文本过长,设置不换行,随内容同行显示

本文介绍了一种简单的方法来解决前端开发中表格单元格内容过长导致的排版问题。通过设置`white-space: nowrap;`样式属性,可以有效避免内容溢出或换行显示,从而提升页面美观度。

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

初次用nowarp点这里: nowrap教程

做Java的又要搞前端,有时候调样式有点烦躁,项目中前端页面都是自己写的,这里分享一个常见的样式调整,虽然很简单,但是没用过的情况下还真不知道怎么调

当td中内容过长时,内容会溢出,换行显示,美观超级差,在td里设置这个属性 "white-space:nowrap   就可以解决排版问题啦     

 <td style="white-space:nowrap">非法闯入闯出亮灯处理:</td>

 不美观的样式:         

美观的样式:

 

另外,nowrap属性可以用在很多标签里面哦,美化排版效果。

 

                                              

根据下面的页面代码,需要编写这个js点击事件,点击明细表中每的name为extendDataFormInfo.value(fd_3e59465a09231a.0.fd_3e5946689e29d2)的输入框,能跳转到对应这个输入框的value面的链接地址,页面代码如下:<tr> <td row="2" column="0,1,2,3" class="td_normal_title" colspan="4" style="width: auto;" width="undefined"> <script> $(function() { var tb = document.getElementById('TABLE_DL_fd_3e59465a09231a'); tb.setAttribute('tbdraggable', 'true'); }); </script> <script> Com_IncludeFile('doclist.js'); </script> <script id="doclist_js" src="/resource/js/doclist.js?s_cache=1754870647847"></script> <script id="doclistdnd_js" src="/resource/js/doclistdnd.js?s_cache=1754870647847"></script> <script> DocList_Info.push('TABLE_DL_fd_3e59465a09231a'); </script> <script> Com_IncludeFile('detailsTableFreeze.css', Com_Parameter.ContextPath + 'sys/xform/designer/resource/css/', 'css', true); </script> <link rel="stylesheet" href="/sys/xform/designer/resource/css/detailsTableFreeze.css?s_cache=1754870647847"> <script> Com_IncludeFile('detailsTableFreeze.js', Com_Parameter.ContextPath + 'sys/xform/designer/resource/js/', 'js', true); </script> <script id="detailsTableFreeze_js" src="/sys/xform/designer/resource/js/detailsTableFreeze.js?s_cache=1754870647847"></script> <script> Com_AddEventListener(window, 'load', function() { setTimeout(function() { for (var i = 0; i < 1; i++) { DocList_AddRow(document.getElementById('TABLE_DL_fd_3e59465a09231a')) }; tableFreezeStarter('TABLE_DL_fd_3e59465a09231a', false, undefined, false, true, 'add'); }, 500); }); </script> <table label="明细表1" id="TABLE_DL_fd_3e59465a09231a" align="center" class="tb_normal" tablename="fd_3e5946528a2834" style="width: 100%;" data-multihead="false" width="100%" showindex="true" showrow="1" showstatisticrow="undefined" showcopyopt="undefined" dataentrymode="multipleRow" required="undefined" performance="undefined" excelexport="undefined" excelimport="undefined" defaultfreezetitle="undefined" defaultfreezecol="undefined" layout2col="undefined" fd_type="detailsTable" tbdraggable="true"> <tbody> <tr class="tr_normal_title" type="titleRow" style="height: 33px;" invalidrow="true"> <td row="1" column="0" align="center" coltype="selectCol" style="width: 15px;"></td> <td row="0" column="1" align="center" class="td_normal_title" coltype="noTitle" style="width: 25px; white-space: nowrap;">序号</td> <td row="0" column="2" align="center" class="td_normal_title"> <label class="xform_label" line="normal" fd_type="textLabel" style="display: inline-block; width: auto; word-break: break-all; overflow-wrap: break-word;;word-break:break-all;;word-wrap:break-word;">文本1</label> </td> <td row="0" column="3" align="center" class="td_normal_title"> <label class="xform_label" line="normal" style="display: inline-block; width: auto; word-break: break-all; overflow-wrap: break-word;;word-break:break-all;;word-wrap:break-word;" fd_type="textLabel">文本3</label> </td> <td row="0" column="4" align="center" class="td_normal_title"></td> <td row="0" column="5" align="center" class="td_normal_title" coltype="blankTitleCol" style="width:48px;"></td> </tr> <tr class="" trdraggable="true" style="cursor: move; user-select: none;"> <td class="" align="center" valign=""><input type="checkbox" name="DocList_Selected" onclick="DocList_SelectRow(this);"></td> <td class="" align="center" valign="">1</td> <td class="" align="center" valign=""> <div class="xform_inputText" canshow="true" fd_type="inputText" style="display: inline-block; width: 147px; word-break: break-all; overflow-wrap: break-word;"> <xformflag flagid="fd_3e59465a09231a.0.fd_3e59465b4a38ce" id="_xform_extendDataFormInfo.value(fd_3e59465a09231a.0.fd_3e59465b4a38ce)" property="extendDataFormInfo.value(fd_3e59465a09231a.0.fd_3e59465b4a38ce)" flagtype="xform_text" _xform_type="text"><input name="extendDataFormInfo.value(fd_3e59465a09231a.0.fd_3e59465b4a38ce)" subject="文本1" title="文本1" onblur="__xformDispatch(this.value, this);" class="inputsgl xform_inputText" value="" type="text" style="display: inline-block; width: 147px; word-break: break-all; overflow-wrap: break-word;width:120px;"> </xformflag> </div> <input name="extendDataFormInfo.value(fd_3e59465a09231a.0.fdId)" value="" type="hidden"> </td> <td class="" align="center" valign=""> <div style="display: inline-block; width: 202px;width: 210px;" class="xform_formula_load"> <xformflag flagid="fd_3e59465a09231a.0.fd_3e5946689e29d2" id="_xform_extendDataFormInfo.value(fd_3e59465a09231a.0.fd_3e5946689e29d2)" property="extendDataFormInfo.value(fd_3e59465a09231a.0.fd_3e5946689e29d2)" flagtype="formula_calculation" _xform_type="formulaCalculation"> <script> Com_IncludeFile('formula_calculation_script.js', '../sys/xform/designer/formula_calculation/'); </script> <script id="formula_calculation_script_js" src="/resource/../sys/xform/designer/formula_calculation/formula_calculation_script.js?s_cache=1754870647847"> </script> <input name="extendDataFormInfo.value(fd_3e59465a09231a.0.fd_3e5946689e29d2)" value="http://192.1.1.92:8080/webroot/decision/view/duchamp?viewlet=crm_project%252F%25E7%2589%25A9%25E6%2596%2599%25E4%25BE%259B%25E9%259C%2580%25E6%259F%25A5%25E8%25AF%25A2%25E9%25A1%25B5%25E9%259D%25A2.fvs&ref_t=design&ref_c=1e33972c-8151-43ff-81bb-d263b846af18&page_number=1&p_material=123" type="hidden" loadtype="autoLoad,manualLoad"><input name="extendDataFormInfo.value(fd_3e59465a09231a.0.fd_3e5946689e29d2_text)" subject="文本3" title="文本3" formula_calculation="true" isrow="true" returntype="text" loadtype="autoLoad,manualLoad" controlsid="fd_3e59465a09231a.fd_3e59465b4a38ce" fdid="fd_3e59465a09231a.0.fd_3e5946689e29d2" right="" readonly="readOnly" class="inputsgl xform_formula_load" value="" type="text" style="display: inline-block; width: 202px;width: 200px;"> </xformflag> </div> </td> <td class="" align="center" valign=""> <label class="xform_linkLabel" fd_type="linkLabel" style="display: inline-block; "><a target="_blank" href="www.baidu.com" style="color: rgb(66, 133, 244); font-weight: normal; font-style: normal; text-decoration: none;" parent_style="display: inline-block; width: 58px;" parent_class="xform_linkLabel">超链接1 </a></label> </td> <td class="" align="center" valign=""> <nobr><span style="cursor:pointer" class="optStyle opt_copy_style" title="复制" onmousedown="DocList_CopyRow();"></span>  <span style="cursor:pointer" class="optStyle opt_del_style" title="删除" onmousedown="DocList_DeleteRow_ClearLast();XFom_RestValidationElements();"></span>   </nobr> </td> </tr> <tr type="statisticRow" invalidrow="true"> <td row="1" column="0" align="center" coltype="selectCol" style="width: 15px;"></td> <td row="2" column="1" align="center" coltype="noFoot" style="width: 25px;"> </td> <td row="2" column="2" align="center"> </td> <td row="2" column="3" align="center"> </td> <td row="2" column="4" align="center"> </td> <td row="2" column="5" align="center" coltype="emptyCell" style="width: 48px;"> </td> </tr> <tr type="optRow" class="tr_normal_opt" invalidrow="true"> <td row="3" column="0" align="center" coltype="optCol" colspan="6" style=""> <div class="tr_normal_opt_content" style="min-width:580px;;"> <div class="tr_normal_opt_l"><label class="opt_ck_style" style="position:relative;top:3px;"><input type="checkbox" name="DocList_SelectAll" onclick="DocList_SelectAllRow(this);"><span style="margin-left: 6px;">全选<span></span></span></label><span style="margin-left:15px;" onclick="DocList_BatchDeleteRow();XFom_RestValidationElements();"><span class="optStyle opt_batchDel_style" style="margin-left:0px; " title="删除"></span><span style="position:relative;top:3px;cursor: pointer;margin-left: 6px;">删除</span></span> </div> <div class="tr_normal_opt_c"><span onclick="DocList_AddRow();XFom_RestValidationElements();"><span class="optStyle opt_add_style" title="添加"></span><span style="position:relative;top:3px;cursor: pointer;margin-left: 6px;">添加</span></span><span style="margin-left:15px;" onclick="DocList_MoveRowBySelect(-1);"><span class="optStyle opt_up_style" title="上移"></span><span style="position:relative;top:3px;cursor: pointer;margin-left: 6px;">上移</span></span><span style="margin-left:15px;" onclick="DocList_MoveRowBySelect(1);"><span class="optStyle opt_down_style" title="下移"></span><span style="position:relative;top:3px;cursor: pointer;margin-left: 6px;">下移</span></span> </div> <div class="tr_normal_opt_r"> </div> </div> </td> </tr> </tbody> </table> </td> </tr>
最新发布
08-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Thinkingcao

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值