简体   繁体   English

如何防止最右边的内联元素在CSS中包装或溢出?

[英]How to prevent rightmost inline element from wrapping or overflowing in CSS?

I give up! 我放弃!

Here's what I'm trying to accomplish: 这是我要完成的工作:

Fiddle : http://jsfiddle.net/Ws5Ts/1/ 小提琴http : //jsfiddle.net/Ws5Ts/1/

Desired behavior : 所需行为

  1. The indicator number is displayed inline with the customer's name (I don't want it fixed to the right of the item div) 指标编号显示在客户姓名的行内(我不想将其固定在item div的右侧)
  2. When the window is resized or if the customer has a very long name the indicator should NOT overflow, but stay at the right side of the item div while the customer's name overflows 调整窗口大小或客户名字很长时,指示器不应溢出,而当客户名字溢出时,指示器应位于item div的右侧

I've been at this for the past two hours trying to use all different kinds of wrapping divs with different positioning but I can't get anything to work exactly how I want it to. 在过去的两个小时中,我一直在尝试使用具有不同定位的所有不同类型的包装divs ,但我无法按照我的要求进行任何操作。

Thanks! 谢谢!

How about putting the indicator outside your current div? 如何将指标置于当前div之外? Just made a really quick example of what I mean here: http://jsfiddle.net/Ws5Ts/3/ 刚刚做了一个非常简单的例子,说明了我的意思: http : //jsfiddle.net/Ws5Ts/3/

My classes aren't very performance correct, but I'm off to bed :) 我的课表现不太好,但是我起床了:)

'

edit: See my comment about margin-left if that suits your layout better 编辑:如果更适合您的布局,请参阅我对左边距的评论

Ok I've spent WAY too much time on this. 好的,我在此上花了太多时间。

Possible solution : http://jsfiddle.net/Ws5Ts/17/ 可能的解决方案http : //jsfiddle.net/Ws5Ts/17/

Approach: 方法:

  1. Reverse the order the of text and indicator and then switch the direction to rtl so that the text overflows to the left. 反转文本和指示器的顺序,然后将direction切换到rtl ,以使文本溢出到左侧。 This keeps the indicator where I want it but the text is now overflowing in the wrong direction. 这样可以将指示器保持在我想要的位置,但是文本现在朝错误的方向溢出。
  2. Make the overflowing text hidden and use it as a spacer. 隐藏溢出的文本,并将其用作分隔符。 Set the duplicate visible absolute-positioned text within a container that has a margin to account for the indicator and set nowrap, hidden overflow and text-overflow on that container. 在具有裕度的容器中设置重复的可见的绝对位置文本,以留出一定的余量来说明指标,并在该容器上设置nowrap,隐藏的溢出和文本溢出。

This seems to work in Chrome, Firefox, Safari and IE9. 这似乎可以在Chrome,Firefox,Safari和IE9中使用。

Anyone else have a less convoluted approach? 还有其他人没有那么费解的方法吗?

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

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