html - 防止 div 换行到下一行

标签 html css

我有一个元素列表,每个元素都有一个右对齐部分和一个左对齐部分。左对齐部分应自由展开,但保持在右对齐部分下方,不会将其推到下一行

发生了什么:

|this is an expanding area of text|
                            |-other stuff-|

应该发生什么:

|this is an expanding area o|-other stuff-|
                           ^
            the last part of the text is cut off here

现在我正在使用 float: rightfloat: left 但如何阻止它们换行?其他东西总是相同的东西,但在不同的浏览器上以不同的宽度呈现,所以我无法指定确切的宽度并使用 overflow: hidden

最佳答案

您可以结合使用overflowfloat 来实现这一点。这是因为 overflow: hidden 建立了一个新的 block formatting context。 .换句话说:

The border box of an element in the normal flow that establishes a new block formatting context (such as an element with 'overflow' other than 'visible') must not overlap the margin box of any floats in the same block formatting context as the element itself (in which case the box itself may become narrower due to the floats).

参见:http://jsfiddle.net/m8x1g0q8/

关于html - 防止 div 换行到下一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29311558/

相关文章:

html - 避免言语分手

html - 这个空间从哪里来?

javascript - 通过页面刷新使用 JQuery 保留添加的类

css - 为什么即使所有参数都设置为 0,文本阴影也可见

asp.net - GridView - 使用 CSS 友好的控件适配器删除 EmptyDataTemplate 和 EmptyDataText

javascript - 使用 JavaScript 将动态数字添加到 CSS map Pin

javascript - 反射型XSS : Why must attack payload be reflected to victim's browser?

html - 我可以用纯 css 创建交叉线背景框吗

css - 更改 DIV 中的不透明度

html - 减少输入文本和底部边框之间的间距