html - 使链接图标与最后一个词断开

标签 html css

<分区>

Possible Duplicate:
Add link icon that breaks with last word?

当文本对于容器而言太长时,我想将最后一个单词换行,而不是仅在它后面显示背景图像。

这是问题的图像:Text not breaking with the background-image.

我想要“太”这个词。与背景图像一起跳转到下一行。

这是 HTML:

<ul>
    <li><a href="#" class="myIcon">The name of some link goes here</a></li>
    <li><a href="#" class="myIcon">The name of some link goes here too.</a></li>
    <li><a href="#" class="myIcon">Here is yet another link that could be used</a></li>
    <li><a href="#" class="myIcon">This could be a really long link that one could try to use also</a></li>
    <li><a href="#">The name of some link goes here.</a></li>
    <li><a href="#">The name of some link goes here.</a></li>
    <li><a href="#">The name of some link goes here.</a></li>
</ul>

这是 CSS:

.myIcon:after {
    height: 16px;
    width: 16px;
    display:inline-block;
    content:'';
    background-image: url("/wps/themes/html/3M.com/images/ui-icons_000000_256x240.png");
    vertical-align:middle;
}

最佳答案

不幸的是,我认为要确保这适用于跨浏览器,您必须将最后一个单词包装在一个 span 中,然后将图标应用于该 span。

<li><a href="#">This could be a really long link that one could try to use <span class="myIcon">also</span></a></li>

CSS:

.myIcon {
    display:inline-block;
    background: url("/wps/themes/html/3M.com/images/ui-icons_000000_256x240.png") no-repeat center right;
    padding-right:16px;
    white-space:nowrap;
    text-decoration:underline;
}

Example is here

关于html - 使链接图标与最后一个词断开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14567596/

上一篇:javascript/css 文本在图像中突出显示

下一篇:javascript - 如何处理未经授权用户的浏览器后退导航

相关文章:

html - CSS中 "ul"元素和 "p"元素之间的匹配缩进

jquery - 第一个 slider 图像未显示在第二个循环中

javascript - 如何在没有设置宽度的情况下更改内容时防止按钮缩小?

html - galaxy s2 的媒体查询

javascript - HTML5 <canvas> 无抗锯齿

html - 移动宽度时 Bootstrap 表单布局不正确

c# - 将 CSS 文件添加到 aspx 文件

html - 背景属性不工作 CSS3

javascript - 当主 url 没有改变但表格内容改变时解析网页

javascript - 用路径创建的圆的 SVG 虚线