简体   繁体   English

最大宽度的内联块不带省略号

[英]inline-block with max-width won't have ellipsis

I had a block element in it there is a inline , and another inline that holds a coloured bullet (used as a mark for the text). 我有一个block元素,其中有一个inline ,另一个inline有一个彩色的项目符号(用作文本的标记)。

 .label-container { width: 160px; /* const width*/ } .label { display: block; max-width: calc(100% - 1em); /* const max-width (parent - ~.highlighted mark)*/ overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } .highlighted-mark:after { content: '●'; } 
 <div class="label-container"> <span class="label">Label</span> <span class="highlighted-mark"></span> </div> 

The text sometimes overflows from the block so I need limiting this and adding an ellipsis in case this happens (ellipsis between after the text, before the mark. 文本有时会从块中溢出,因此我需要对此加以限制,以防万一(在文本之后,标记之前的省略号之间添加省略号)。

In order to let the ellipsis show I had to turn the text element to a block with constant width. 为了让省略号显示,我必须将text元素转换为具有恒定宽度的块。 For the block to act inline -ish (it had to behave as an uniform inline text) I added the float: left . 为了使该块能够像inline一样(必须表现为统一的inline文本),我添加了float: left

I want to get other inline display properties that I do not get as it is above and I also do not want to do such a bad parctice (forcing inline properties onto a block only because of the need of ellipsis). 我想获得我上面没有的其他内联显示属性,并且我也不想做这样一个糟糕的表述(仅由于省略号而将内联属性强制到一个块上 )。 I did not like this use of reduction of widths in order to fill the parent .label-container ; 我不喜欢这种减少宽度的方式来填充父.label-container ; I'd hope for something like flex-grow if it'd have act like max-width . 我希望能像flex-grow这样的东西,就像max-width [I already tried inline-block , which is enough for me regarding its inline -like-properties, but it won't work! [我已经尝试了inline-block ,就其inline -like-properties而言,这对我来说已经足够了,但是它行不通! I prefer not using dotdotdot though I have a license]. 尽管我有许可证,但我更喜欢不使用dotdotdot。

Any proposal for a change? 有任何更改建议吗? :{ :{

You can probably try flexbox like this: 您可能可以这样尝试flexbox:

 .label-container { width: 160px; /* const width*/ border:1px solid; display:flex; } .label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } .highlighted-mark:after { content: '●'; } 
 <div class="label-container"> <span class="label">Label</span> <span class="highlighted-mark"></span> </div> <div class="label-container"> <span class="label">very looooooooong Label</span> <span class="highlighted-mark"></span> </div> 

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

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