在 HTML 行文本被右对齐内容遮盖之前溢出

发布于 2024-07-25 17:02:24 字数 1929 浏览 1 评论 0原文

我有一些文本显示在具有固定宽度的容器中的单行上。 如果文本不能包含在容器的宽度内,则溢出将被隐藏。 三个状态图标的任意组合可能会出现在容器的右侧。 如果出现任何这些图标,我希望在第一个图标出现之前隐藏文本溢出,以便文本不会在图标后面显得模糊。

如何使文本溢出,使其不会在图标下流动(理想情况下仅使用 CSS,而不需要诉诸 JavaScript)?

我开始使用的 CSS 和 HTML 示例(两者都不是)其中具体设定)如下。 这是一个代码的实时示例,它也说明了所需的结果(注意它有一个嵌入在 CSS 中的背景图像)使用数据 URI 方案,因此不适用于 Internet Explorer 8 之前的版本。

CSS:

.line {
  position: relative;
  width: 200px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.star, .circle, .flag {
  position: absolute;
  top: 3px;
  height: 23px;
  width: 15px;
  background-image: url(icons.png);
}

.star {
  right: 30px;
}

.circle {
  right: 15px;
  background-position: -17px 0;
}

.flag {
  right: 0;
  background-position: -32px 0;
}

HTML:

<div class="line">This is some text that should have overflow that is hidden.</div>
<div class="line">
    This is some text that should have overflow that is hidden.
    <div class="flag"></div>
</div>
<div class="line">
    This is some text that should have overflow that is hidden.
    <div class="circle"></div><div class="flag"></div>
</div>
<div class="line">
    This is some text that should have overflow that is hidden.
    <div class="star"></div><div class="circle"></div><div class="flag"></div>
</div>
<div class="line">
    This is some text that should have overflow that is hidden.
    <div class="star"></div><div class="flag"></div>
</div>
<div class="line">
    This is some text that should have overflow that is hidden.
    <div class="circle"></div>
</div>

I've got some text that is displayed on a single line in a container that has a fixed width. If the text can't be contained within the width of the container the overflow is hidden. Any combination of three status icons may appear positioned from the right hand side of the container. If any of these icons appear I'd like the text overflow to be hidden before the first icon appears so the text does not appear obscured behind the icons.

How can I overflow the text so it doesn't flow under the icons (ideally using only CSS and not needing to resort to JavaScript)?

An example of the CSS and HTML I've started from (neither of which are set in concrete) follows. Here's a live example of the code which also illustrates the desired result (note it has an background image inlined in the CSS using the data URI scheme so won't work in versions of Internet Explorer earlier than 8).

CSS:

.line {
  position: relative;
  width: 200px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.star, .circle, .flag {
  position: absolute;
  top: 3px;
  height: 23px;
  width: 15px;
  background-image: url(icons.png);
}

.star {
  right: 30px;
}

.circle {
  right: 15px;
  background-position: -17px 0;
}

.flag {
  right: 0;
  background-position: -32px 0;
}

HTML:

<div class="line">This is some text that should have overflow that is hidden.</div>
<div class="line">
    This is some text that should have overflow that is hidden.
    <div class="flag"></div>
</div>
<div class="line">
    This is some text that should have overflow that is hidden.
    <div class="circle"></div><div class="flag"></div>
</div>
<div class="line">
    This is some text that should have overflow that is hidden.
    <div class="star"></div><div class="circle"></div><div class="flag"></div>
</div>
<div class="line">
    This is some text that should have overflow that is hidden.
    <div class="star"></div><div class="flag"></div>
</div>
<div class="line">
    This is some text that should have overflow that is hidden.
    <div class="circle"></div>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

旧城烟雨 2024-08-01 17:02:24

您可以直接在包含文本的 div 中使用背景图像,并使用填充来为图标释放一些空间。

编辑:

这是一个工作示例,但我无法让“nowrap”工作,所以我通过使用高度进行作弊:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<style type="text/css" media="screen">
.star {
    background-image: url('data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00.%00%00%00%10%08%06%00%00%00i%C9M%EA%00%00%00tIDATH%C7%ED%96Q%0A%C0%20%0CC%7B%98%C9%EE%7F%C2y%01%91%2C%BE%0C%19%16%FCl%F3%AC5Z%F5%C7%B8%AF%F6%1CpQOYr%11%02%80%00%96X%5CpG%D4%06~%B3%E3Y%A1%95%8E!%A3%91%10ws%A3G%9D%D88v%BB)GP%C0Q%5B%A2%EC%2Cf%C1%AB%A2%04%B8%05%3FJ%A4%BA%1E%7B%F8%14%ABK%8E%9A%DDu%C59%EA%A38%FF%A4%DD%A2%03%C8d%24%84%B6%AC%BF%C0%00%00%00%00IEND%AEB%60%82');
    background-position: right;
    background-repeat: no-repeat;
    padding-right: 30px;
}

.line {
    width: 200px;
    overflow: hidden;
    height: 20px;
}
</style>
</head>
<body>
    <div class="star line">This is some text that that should have overflow that is hidden.</div>
    <div class="star line" style="padding-right: 0px;">This is some text that that should have overflow that is hidden.</div>
</body>
</html>

似乎您必须使用单个图像而不是精灵,但您可以直接将填充添加到星形、圆形和旗帜级。

You could make use the background image directly in the div that contains the text and use padding to free some space for the icons.

EDIT:

Here is a working example, but I couldn't get "nowrap" to work, so I cheated by using a height:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<style type="text/css" media="screen">
.star {
    background-image: url('data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00.%00%00%00%10%08%06%00%00%00i%C9M%EA%00%00%00tIDATH%C7%ED%96Q%0A%C0%20%0CC%7B%98%C9%EE%7F%C2y%01%91%2C%BE%0C%19%16%FCl%F3%AC5Z%F5%C7%B8%AF%F6%1CpQOYr%11%02%80%00%96X%5CpG%D4%06~%B3%E3Y%A1%95%8E!%A3%91%10ws%A3G%9D%D88v%BB)GP%C0Q%5B%A2%EC%2Cf%C1%AB%A2%04%B8%05%3FJ%A4%BA%1E%7B%F8%14%ABK%8E%9A%DDu%C59%EA%A38%FF%A4%DD%A2%03%C8d%24%84%B6%AC%BF%C0%00%00%00%00IEND%AEB%60%82');
    background-position: right;
    background-repeat: no-repeat;
    padding-right: 30px;
}

.line {
    width: 200px;
    overflow: hidden;
    height: 20px;
}
</style>
</head>
<body>
    <div class="star line">This is some text that that should have overflow that is hidden.</div>
    <div class="star line" style="padding-right: 0px;">This is some text that that should have overflow that is hidden.</div>
</body>
</html>

And it seems like you have to use single images instead of sprites, but you could add the padding directly to the star, circle and flag class.

辞取 2024-08-01 17:02:24

也许我没有正确理解你的意思,但是将 .star、.circle、.flag 的背景颜色简单地设置为“白色”并在它们上使用“z-index”怎么样? 可以这么说,这当然是一个黑客,但也许对你有用。

更新

刚刚根据您的代码进行了尝试。 仅适用于 FF、Opera、IE8:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
  <title>Sandbox</title>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  <style type="text/css" media="screen">
  .line{
    position: relative;
    width: 200px;
  }  
  .star,
  .circle,
  .flag{
    top: 3px;
    height: 23px;
    width: 15px;
    background-repeat:no-repeat;
    background-image: url('data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00.%00%00%00%10%08%06%00%00%00i%C9M%EA%00%00%00tIDATH%C7%ED%96Q%0A%C0%20%0CC%7B%98%C9%EE%7F%C2y%01%91%2C%BE%0C%19%16%FCl%F3%AC5Z%F5%C7%B8%AF%F6%1CpQOYr%11%02%80%00%96X%5CpG%D4%06~%B3%E3Y%A1%95%8E!%A3%91%10ws%A3G%9D%D88v%BB)GP%C0Q%5B%A2%EC%2Cf%C1%AB%A2%04%B8%05%3FJ%A4%BA%1E%7B%F8%14%ABK%8E%9A%DDu%C59%EA%A38%FF%A4%DD%A2%03%C8d%24%84%B6%AC%BF%C0%00%00%00%00IEND%AEB%60%82');
  }  
  .star{
    right: 30px;
  }  
  .circle{
    right: 15px;
    background-position: -17px 0;
  }  
  .flag{
    right: 0;
    background-position: -32px 0;
  }
  </style>
  </head>
  <body>
    <h1>Current results:</h1>     
    <div class="line" style="background-color:red;">        
        <div class="star" style="display:inline;float:right"></div>
        <div class="flag" style="display:inline;float:right"></div>
        <div style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">This is some text that should have overflow that is hidden.</div>
    </div>
  </body>
</html>

Maybe I don't understand you correctly, but what about setting the background-color of .star, .circle, .flag simply to "white" and use "z-index" on them? It certainly is a hack so to speak, but maybe will work for you.

Update

Just made an attempt based on your code. Only working on FF, Opera, IE8:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
  <title>Sandbox</title>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  <style type="text/css" media="screen">
  .line{
    position: relative;
    width: 200px;
  }  
  .star,
  .circle,
  .flag{
    top: 3px;
    height: 23px;
    width: 15px;
    background-repeat:no-repeat;
    background-image: url('data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00.%00%00%00%10%08%06%00%00%00i%C9M%EA%00%00%00tIDATH%C7%ED%96Q%0A%C0%20%0CC%7B%98%C9%EE%7F%C2y%01%91%2C%BE%0C%19%16%FCl%F3%AC5Z%F5%C7%B8%AF%F6%1CpQOYr%11%02%80%00%96X%5CpG%D4%06~%B3%E3Y%A1%95%8E!%A3%91%10ws%A3G%9D%D88v%BB)GP%C0Q%5B%A2%EC%2Cf%C1%AB%A2%04%B8%05%3FJ%A4%BA%1E%7B%F8%14%ABK%8E%9A%DDu%C59%EA%A38%FF%A4%DD%A2%03%C8d%24%84%B6%AC%BF%C0%00%00%00%00IEND%AEB%60%82');
  }  
  .star{
    right: 30px;
  }  
  .circle{
    right: 15px;
    background-position: -17px 0;
  }  
  .flag{
    right: 0;
    background-position: -32px 0;
  }
  </style>
  </head>
  <body>
    <h1>Current results:</h1>     
    <div class="line" style="background-color:red;">        
        <div class="star" style="display:inline;float:right"></div>
        <div class="flag" style="display:inline;float:right"></div>
        <div style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">This is some text that should have overflow that is hidden.</div>
    </div>
  </body>
</html>
撕心裂肺的伤痛 2024-08-01 17:02:24

您的问题是您希望根据特定类型的子级标记的数量影响父级标记的呈现。 如果没有一些程序性干预,这是不可能的。

如果您以编程方式生成这些列表,我建议只添加三个类来指定外部 div 的线宽:

.line {
  position: relative;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.noicon {
   width: 200px
}

.oneicon {
   width: 183px
}

.twoicon {
   width: 168px
}

.threeicon {
   width: 154px
}

<div class="line noicon">This is some text that should have overflow that is hidden.</div>
<div class="line oneicon">
        This is some text that should have overflow that is hidden.
        <div class="flag"></div>
</div>
<div class="line twoicon">
        This is some text that should have overflow that is hidden.
        <div class="star"></div><div class="flag"></div>
</div>
<div class="line threeicon">
        This is some text that should have overflow that is hidden.
        <div class="star"></div><div class="circle"></div><div class="flag"></div>
</div>

否则,您最好的选择可能是使用 Javascript 动态缩小框。

Your problem is that you want to affect the rendering of a parent tag based on the number of its children of a particular type. That's just not possible without some programmatic intervention.

If you're programmatically generating these lists, I'd suggests just adding three classes which specify the width of the line to the outer div:

.line {
  position: relative;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.noicon {
   width: 200px
}

.oneicon {
   width: 183px
}

.twoicon {
   width: 168px
}

.threeicon {
   width: 154px
}

<div class="line noicon">This is some text that should have overflow that is hidden.</div>
<div class="line oneicon">
        This is some text that should have overflow that is hidden.
        <div class="flag"></div>
</div>
<div class="line twoicon">
        This is some text that should have overflow that is hidden.
        <div class="star"></div><div class="flag"></div>
</div>
<div class="line threeicon">
        This is some text that should have overflow that is hidden.
        <div class="star"></div><div class="circle"></div><div class="flag"></div>
</div>

Otherwise, your best option might be to use Javascript to dynamically shrink the boxes.

绿光 2024-08-01 17:02:24

让这些图标影响文本宽度的最简单方法是将它们放在它前面(无论如何它们都是绝对定位的),并给文本本身一个容器(我很确定你需要它,无论你采取哪种方式)。 所以你最终会得到这样的结果:

<div class="line">This is some text that should have overflow that is hidden.</div>
<div class="line">
    <div class="flag"></div>
    <div class="text">This is some text that should have overflow that is hidden.</div>
</div>
<div class="line">
    <div class="circle"></div>
    <div class="flag"></div>
    <div class="text">This is some text that should have overflow that is hidden.</div>
</div>

这是你需要的唯一新的 CSS(除了问题中的 CSS 之外):

.text {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.flag   ~ .text { width: 183px; }
.circle ~ .text { width: 168px; }
.star   ~ .text { width: 154px; }

.text 规则与 .line 相同div 您用于自己的工作示例。 真正的“魔力”发生在最后的规则中,它们是我将图像 div 向上移动的原因。 这允许您使用 CSS3 同级选择器 来设置 .text 的宽度 div 基于图标的存在。 您可以简单地让 CSS 级联通过按从右到左的顺序列出图标类来处理宽度。

顺便说一句,我不得不说这里有相当多的 div,所以没有任何迹象表明它的实际含义。 您首先关心的应该始终是创建语义 HTML。

我可能想将文本放在段落标签中,将图标放在列表中,并为每个列表项提供文本描述(用 CSS 隐藏)。 话又说回来,也许这实际上并不合适(也许图标 div 确实应该出现在文本之后); 我不知道。 如果图标出现在列表中,同级选择器将需要一些帮助......

The easiest way to be able to let those icons affect the width of the text is to have them precede it (they're absolutely positioned anyway), and to give text itself a container as well (I'm pretty sure you need that, whichever way you do it). So you end up with this:

<div class="line">This is some text that should have overflow that is hidden.</div>
<div class="line">
    <div class="flag"></div>
    <div class="text">This is some text that should have overflow that is hidden.</div>
</div>
<div class="line">
    <div class="circle"></div>
    <div class="flag"></div>
    <div class="text">This is some text that should have overflow that is hidden.</div>
</div>

Here's the only new CSS you need to make that work (in addition to the CSS in the question):

.text {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.flag   ~ .text { width: 183px; }
.circle ~ .text { width: 168px; }
.star   ~ .text { width: 154px; }

The .text rule is the same as the .line div you used for your own working example. The real "magic" happens in those last rules, and they're the reason I moved the image divs up. That allows you to use the CSS3 sibling selector to set the width of the .text div based on the presence of the icons. You can simply let the CSS cascade take care of the width by listing the icon classes in right-to-left order.

As a side note, I do have to say that there are rather a lot of divs here, so there's no indication of what it actually means. Your first concern should always be to create semantic HTML.

I'd probably want to put the text in paragraph tags and the icons in a list, and give each list item a textual description as well (hiding it with CSS). Then again, maybe that's not actually appropriate (and maybe the icon divs should really come after the text); I can't tell. And if the icons go in a list, the sibling selector will need some help...

何以笙箫默 2024-08-01 17:02:24

我无法评论Merkuro的回答和你的回应(太少了),所以我在这里添加:
您可以只使用不透明图像覆盖的线的占位符图像,这样,一旦放置,它将覆盖文本和线,但背景线似乎不间断,因为图像有一条线与图像对齐其背后的实线。 您可以使用 hover: 在线条改变颜色等时切换图像(我目前能想到的最好的)

此外,如果您使用仅带有一个符号(星形、圆形、旗帜)的单独图像)并用不透明的空白将图像向右填充到您想要覆盖的宽度,您会得到类似的东西(我尽了最大努力对base64图像进行编码,但它只适用于FF。CSS应该与正确链接的图像)。

CSS:

.line {
  position: relative;
  width: 200px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.star,
.circle,
.flag {
  position: absolute;
  top: 3px;
  height: 23px;
  right: 0px;
}

.star {
  width: 45px;
  background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC4AAAAQCAMAAABeF73YAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAwBQTFRFAAAA%2F%2F%2F%2FAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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sn1u5H20Tsz%2BQHT4AKfEabvTAAAAABJRU5ErkJggg%3D%3D');
  //background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD4AAAAQCAIAAADBBVtVAAAAfUlEQVR4nNVVQQrAIAyz4v%2B%2F3B0K%0AzuEYth0p6UmF1hiSKKraOKvnR4hIfkigfoBeVVnoRnkJ8cSsi9emhwQD3O9m%2FQQTJrXcrN%2Bdb%2FQj%0Aozau9R0l%2BIsgtmkc%2Bi4YcESOZP8UCT7au926Xvy9nYftKW5bIx9AbNN4OJYXccJcMFQtIo2LoIEA%0AAAAASUVORK5CYII%3D');
}

.circle {
  width: 30px;
  background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC4AAAAQCAMAAABeF73YAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAwBQTFRFAAAA%2F%2F%2F%2FAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZ3bsYwAAABh0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjM2qefiJQAAAENJREFUKFO10UEOACAIA8Hy%2F08rSPC6NZHzpBCqsEaWjieuHLKnUGnkk7cm3ucTDuJ3usn%2F3u4%2Bsj2uicBjUPU3zuQLvrYCj5S%2FhI4AAAAASUVORK5CYII%3D');
  //background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC4AAAAQCAIAAADmq9q9AAAAaUlEQVR4nO1VQQ7AIAhrjf%2F%2FMjuO%0AGOVAF8VkvWFiKAUKzQw10E4TeFGISlc%2Bk%2FSh2Ou8KgOP6csOKqusCptCs5KhEpeeFuZyVeJNSe%2FR%0A5apgXbpiLQ0AST9rcRhkFS1OcttvTyn%2FyzzBA%2B9YHizbV3zJAAAAAElFTkSuQmCC');
}

.flag {
  width: 15px;
  background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC4AAAAQCAMAAABeF73YAAAAAXNSR0IArs4c6QAAAARnQU1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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZ3bsYwAAABh0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjM2qefiJQAAAExJREFUKFO10LECACAERVH%2B%2F6dTJJtryNB06CE6KhlpPVyyumbjD%2FdfVd6N3jleFqALJzpXRdjD2LJQO48X9ASn48NNOfSX%2FeXgKpssziECqaokJE4AAAAASUVORK5CYII%3D');
  //background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB8AAAAQCAIAAABhmjO7AAAAbElEQVR4nLWSUQ7AIAhDqdn9r8w%2B%0ASJyJ2pki%2FVPio0Lh7lamVoc2s0d%2BCYBUYyQKnXM7WqSfcEPK3HdBmO%2BvbXXZEnIi%2B%2FQJIeudm9Pp%0AJ5%2FOeufpTNF%2F7bfoP1rgx1mkWrtVPZEfAlvIBTrRC7wOMBc8CAoqAAAAAElFTkSuQmCC');
}

I can't comment on Merkuro's answer and your response (too few points), so I'm adding this here:
You could just use a placeholder image of the line covered by the opaque img so that, once placed, it'll cover the text and the line, but the background line is seemingly uninterrupted as the image has a line that aligns up neatly with the real line behind it. And you could use hover: to switch images when the line changes colour, etc. (best I could think of at the moment)

Also if you use seperate images with just one symbol (star, circle, flag) and pad the images to the right with opaque whitespace upto the width you want to cover, you'd have something like this (I did my best to encode the base64 images, but it only works in FF. The CSS should work correctly with proper linked images).

CSS:

.line {
  position: relative;
  width: 200px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.star,
.circle,
.flag {
  position: absolute;
  top: 3px;
  height: 23px;
  right: 0px;
}

.star {
  width: 45px;
  background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC4AAAAQCAMAAABeF73YAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnL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AAAAAAAAAAAAAAAAAAAAAAZ3bsYwAAABh0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjM2qefiJQAAAE5JREFUKFOd0jEOACAIA8Dy%2F0%2BLDQY3WlhcDlIJCKtQ%2Br1D844D2vhSOk%2FZNf07pxs6GKYaptFX0tALesXNMAwipfmg4sn1u5H20Tsz%2BQHT4AKfEabvTAAAAABJRU5ErkJggg%3D%3D');
  //background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD4AAAAQCAIAAADBBVtVAAAAfUlEQVR4nNVVQQrAIAyz4v%2B%2F3B0K%0AzuEYth0p6UmF1hiSKKraOKvnR4hIfkigfoBeVVnoRnkJ8cSsi9emhwQD3O9m%2FQQTJrXcrN%2Bdb%2FQj%0Aozau9R0l%2BIsgtmkc%2Bi4YcESOZP8UCT7au926Xvy9nYftKW5bIx9AbNN4OJYXccJcMFQtIo2LoIEA%0AAAAASUVORK5CYII%3D');
}

.circle {
  width: 30px;
  background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC4AAAAQCAMAAABeF73YAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAwBQTFRFAAAA%2F%2F%2F%2FAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZ3bsYwAAABh0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjM2qefiJQAAAExJREFUKFO10LECACAERVH%2B%2F6dTJJtryNB06CE6KhlpPVyyumbjD%2FdfVd6N3jleFqALJzpXRdjD2LJQO48X9ASn48NNOfSX%2FeXgKpssziECqaokJE4AAAAASUVORK5CYII%3D');
  //background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB8AAAAQCAIAAABhmjO7AAAAbElEQVR4nLWSUQ7AIAhDqdn9r8w%2B%0ASJyJ2pki%2FVPio0Lh7lamVoc2s0d%2BCYBUYyQKnXM7WqSfcEPK3HdBmO%2BvbXXZEnIi%2B%2FQJIeudm9Pp%0AJ5%2FOeufpTNF%2F7bfoP1rgx1mkWrtVPZEfAlvIBTrRC7wOMBc8CAoqAAAAAElFTkSuQmCC');
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文