jquery - 如果内容从第一行流出,请将 <a> 标记移至新行?

标签 jquery html css

我正在努力实现以下目标,如果标签的内容从一行流到另一行,则将标签移至新行,这样您就可以明白我的意思了 http://jsfiddle.net/sNyzX/第一个示例(红色)显示了我现在的情况,第二个示例(橙色)显示了所需的效果,但是没有那个 <br>标签。这可以用纯 html 和 css 实现吗,如果不是,jQuery 解决方案也可以。

<div id="example1">
    Hi there This is some text and <a href="#"> this is the link! </a>
</div>

<div id="example2">
    Hi there This is some text and <br> <a href="#"> this is the link! </a>
</div>

CSS:

#example1 {
    background: red;
    width: 145px;
}

#example2 {
    background: orange;
    width: 145px;
    margin-top: 20px;
}

最佳答案

添加:

a {
    white-space: pre;
}

关于jquery - 如果内容从第一行流出,请将 <a> 标记移至新行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16625021/

相关文章:

javascript - 如何判断 JavaScript 和/或 jQuery 对象的类型

html - "Responsive"buttons with::before and::after shape

html - 横向导航让当前的li更高

html - 降低行内li的高度?

javascript - 在 bootstrap 4 中使用导航栏时如何使表头固定

javascript - 将 Javascript 变量解析为 CSS 变量

CSS 用 :checked not working 链接相邻兄弟

javascript - 从日期和时间字符串中删除时间

javascript/jquery 以短格式将 utc 转换为本地时间

javascript - jQuery - 当我的鼠标悬停在它上面时如何获取任何单词的值