html - 截断绝对定位的 div 中的文本

标签 html css

这是我正在尝试做的 JSFiddle:JSFiddle Example

它是响应式的,而且宽度很大,这正是我想要的,像这样:

enter image description here

但是在小尺寸的情况下,它会与另一个文本重叠和/或打断这些行,如下所示:

enter image description here

还有这个:

enter image description here

这是我对文本的 CSS:

.giro-nome {
    position: absolute;
    top: 25%;
}

.giro-percentual {
    position: absolute;
    right: 0;
    top: 25%;
    font-weight: 700;
}

我只想在一行中停止文本,像这样(预期的,不是真实的):

enter image description here

这可能吗?可能不像我正在做的那样使用 absolute,但我不知道另一种方法。

谢谢先进。

最佳答案

text-overflow: ellipsis ;正是您要找的。

8.2. Overflow Ellipsis: the ‘text-overflow’ property

This property specifies rendering when inline content overflows its block container element ("the block") in its inline progression direction that has ‘overflow’ other than ‘visible’. Text can overflow for example when it is prevented from wrapping (e.g. due to ‘white-space:nowrap’ or a single word is too long to fit). Values have the following meanings:

ellipsis Render an ellipsis character (U+2026) to represent clipped inline content. Implementations may substitute a more language/script-appropriate ellipsis character, or three dots "..." if the ellipsis character is unavailable.

但是你应该首先指定绝对定位元素的宽度。通过left/right属性,或通过其他方法,例如 width: 90%width: calc(100% - 80px) :

EXAMPLE HERE

.giro-nome {
    position: absolute;
    top: 25%;
    left: 0; right: 80px;  /* Equal to > width: calc(100% - 80px) */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

关于html - 截断绝对定位的 div 中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25528056/

相关文章:

javascript - jQuery UI 奇怪的调整大小行为

javascript - 如何用图像替换表单按钮,并在悬停时更改图像?还有 Sprite 与单独的图像?

javascript - 在each循环中选择div

jquery - 使用 jQuery 保存 html 表单布局和值

javascript - 无法创建动态 div 以在单击和返回时更改大小

css - 如何增加日期选择器的年份下拉字体大小

html - CSS - 多个 100% 高度 div?

javascript - Div 没有填满新内容

html - 如果没有宽度的父容器,宽度 em 指的是什么?

html - Internet Explorer 8 - 打印页面的标题