【问题标题】:CSS: how to put element next to last line of textCSS:如何将元素放在最后一行文本旁边
【发布时间】:2015-10-15 07:40:21
【问题描述】:

我有一个span,里面有文字,它有一个max-width 属性。 有时里面的文本比最大宽度大,所以跨度会断线。到这里没问题。

但是当文本中断时,它旁边的元素看起来也没有下降。这是一个例子

<span> some text with fine width</span> <div> the div</div> 这将输出如下内容: some text with fine width the div

但是当文本很长时,它看起来像这样:

<span> some text with more the max width</span> <div> the div</div>

some text with more the div the max width

我希望它看起来像这样:

some text with more the max width the div

我设法做到了:

some text with more the max width the div

但我希望该 div 紧挨着文本的最后一行。 这可以通过 css 实现吗?

【问题讨论】:

  • 请将您当前的 HTML 和 CSS 添加到您的问题中,以便我们重现该问题。
  • 你的CSS文件在哪里?

标签: html css


【解决方案1】:

在css中为该元素添加样式:

display: inline;

【讨论】:

    【解决方案2】:

    伪元素之后

    如果我正确理解您的问题,这就是您要搜索的内容:

    .stuff:after{
        content: "I am Groot.";
        display: inline-block;
        color: limegreen;
    }
    

    :after 被插入到结束标记之前。同样:before 就在开始标签之后

    JSFiddle

    【讨论】:

    • 这正是我需要的谢谢!但是一个问题。后面的内容是否必须在 css 中硬编码?
    • 不幸的是:是的。通常它不用于内容,而是用于图标或样式目的。你也不能输入html。您可以通过在<style> 标签中使用 php、javascript 添加它来动态生成它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-25
    • 2016-01-06
    • 2014-04-14
    • 2022-08-18
    • 2016-01-21
    • 2011-10-12
    • 1970-01-01
    相关资源
    最近更新 更多