简体   繁体   English

文字换行 <li> 标签

[英]Text wrap inside <li> tag

I have the following structure on a div: 我在div上具有以下结构:

<div class="box1" id="infobox">
<h2> Point characteristics: </h2>
<div style="padding-left:30px" align="left">
<ul>
    <li class="infobox_list"><b>X value: </b><span class="clsshorted infobox_text" id="infobox_xvalue"> </span></li>
    <li class="infobox_list"><b>Y value: </b><span class="clsshorted infobox_text" id="infobox_yvalue"> </span></li>        
    <li class="infobox_list"><b>Description: </b><span class="clsshorted infobox_text" id="infobox_description"> </span></li>
</ul>


Where the class "infobox_list" contains the following CSS: 其中“ infobox_list”类包含以下CSS:

.infobox_list {
    padding: 0px 0px 10px 0px;
    width: 500px;
}

The class "clsshorted" contains the following CSS: 类“ clsshorted”包含以下CSS:

span.clsshorted {
    vertical-align: bottom; 
    overflow: hidden; 
    white-space: nowrap; 
    display: inline-block;
    text-overflow: ellipsis;        
    width: 300px;       
}

And the class "infobox_text" contains the following CSS: 并且“ infobox_text”类包含以下CSS:

.infobox_text {
    overflow: auto;
    white-space: nowrap;
    word-wrap:break-word;   
}

Example can be seen at: https://jsfiddle.net/nowv94yz/ 可以在以下示例中看到示例: https : //jsfiddle.net/nowv94yz/

I have been encountering two problems which I don't know how to deal with them: 我遇到了两个我不知道如何处理的问题:

  1. The first problem I have been encountering is that I toggle, by using the "toggleClass()" function from JQuery, the class "clsshorted". 我遇到的第一个问题是,我使用JQuery的“ toggleClass()”函数切换了“ clsshorted”类。 When the clsshorted class is active I would like that the "ellipsised" text from the "text-overflow" property is ellipted at the end of the <li> tag (which as it can be seen at the CSS is 500px width) instead than on the 300px that I input. 当clsshorted类处于活动状态时,我希望“ text-overflow”属性中的“省略”文本在<li>标记的末尾省略(在CSS上可以看到是500px宽度),而不是在我输入的300px上。 The thing is that as the string is so long (and with no spaces) that if I do not input that 300px it does not ellipsisate the text or it does outside the box size... (check jsfiddle avobe to see the problem) 事实是,由于字符串太长(且没有空格),因此如果我不输入300px,则不会省略文本或超出框大小...(请检查jsfiddle avobe以查看问题)

  2. The second problem I have been encountering is that when the "clsshort" class is not active, and thus only the "infobox_text" class is active, I would like this large string without spaces to appear completely displayed, but respecting the borders of the <li> tag. 我遇到的第二个问题是,当“ clsshort”类未处于活动状态,因此只有“ infobox_text”类处于活动状态时,我希望这个没有空格的大字符串能够完全显示出来,但要注意<li>标签。 This means that if the <li> tag is 500px width, and the string would need 1501px to be displayed, 4 justified rows appear containing the string cutted on those part where the word reaches the end of the content of the box (500px) 这意味着,如果<li>标签的宽度为500px,则该字符串需要显示1501px,将出现4个对齐的行,其中包含该单词到达框内容末尾的部分(500px)上切掉的字符串。

Any ideas on how to do this? 有关如何执行此操作的任何想法?

Thank you in advance! 先感谢您!

For the second problem, you just need to remove white-space: nowrap; 对于第二个问题,您只需要删除white-space: nowrap; from .infobox_text . 来自.infobox_text

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM