html - CSS 文本溢出取决于兄弟元素之外的剩余空间

标签 html siblings css

我正在尝试设置一个列表条目的样式,该列表条目由左侧的文本和右侧的操作元素组成。 如果文本较长,则可用空间文本应由省略号替换。

 - This is a list entry with text that is… [>]

如果将鼠标悬停在列表条目上,将显示更多操作元素,例如:

 - This is a list entry with text tha… [x] [>]

我更喜欢纯 CSS 解决方案,而不依赖于 JS。

这就是我想出的http://jsfiddle.net/rBthS/265/ 但不知何故,我觉得我错过了什么。

一定有更直接的方法。你能帮忙吗?

最佳答案

在仔细考虑之后,我正在寻找的更简单的解决方案是 http://jsfiddle.net/rBthS/272/

<ul>
  <li>
    <div style="float: right;">Foo Bar</div>
    <div style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap">
      More text then this can handle …
    </div>
  </li>
  <li>…</li>
</ul>

关于html - CSS 文本溢出取决于兄弟元素之外的剩余空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17365839/

相关文章:

html - 多语言网站的元标签和 RSS

javascript - 仅当单击外部 li 时才触发事件

css - 是否有 "previous sibling"选择器?

mysql - 在嵌套集模型中排序 sibling

html - 背景透明的顶部

javascript - iOS Mobile Safari Service Worker 缓存限制

html - Bootstrap 调整列

android - 不是同一 RelativeLayout 中的同级

html - 忽略字体系列规则

html - 如何仅为 Bootstrap 容器流体的填充填充背景颜色?