侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

css – prevent:after元素包装到下一行

2022-07-02 星期六 / 0 评论 / 0 点赞 / 95 阅读 / 1192 字

我有这个HTML: <ul> <li class="completed"><a href="#">I want the icon to stay on the same line as

...我有这个HTML:

<ul>    <li class="completed"><a href="#">I want the icon to stay on the same line as this last <strong>word</strong></li></ul>

我使用:after伪元素附加一个图标:

ul li.completed a:after {    background:transparent url(img.png) no-repeat;     content: '';    display:inline-block;    width: 24px;    height: 16px;}

问题:如果可用宽度太小,图标会换行到下一行。我希望它保持在与它附加到的链接的最后一个字的同一行:

这是可行的,没有添加“nowrap”到整个链接(我想要的词,只是不是图标)。

参见jsFiddle here。

.

解决方法

. 您可以将图像添加到最后一个词。这将使它打破在一起。

添加一个类到word
< strong class =“test”> word< / strong>

和.test:after {…

http://jsfiddle.net/52dkR/

诀窍是让这个类是inline-block

如果你想保持下划线看到这一点。

http://jsfiddle.net/atcJJ/

add text-decoration:inherit;

. ..

广告 广告

评论区