移动<a> tag to new line if it&#39;s content flows out of the first line?</a>

时间:2013-05-18 13:53:00

标签: jquery html css html5 css3

我正在尝试实现以下功能,如果内容从一行流向另一行,请将标记移动到新行,这样您就可以看到我在这里的含义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;
}

5 个答案:

答案 0 :(得分:3)

添加:

a {
    white-space: pre;
}

答案 1 :(得分:2)

是的,你可以!

刚刚放

#example1 a {
    display: block   
}

jsFiddle here

答案 2 :(得分:1)

我认为你应该使用

 word-break:break-word;

长话以闯入。

#example1 {
    background: red;
    width: 145px;
    word-break:break-word;
}

JS Fiddle Demo

答案 3 :(得分:1)

将其添加到样式表

#example1 a {
    white-space: nowrap;
}

答案 4 :(得分:0)

只需将链接的显示属性设置为阻止,它就会始终将链接移动到新行。

#example1 a {
    display: block;
}

您可以查看此页面以了解展示属性的工作原理: http://www.tutorialrepublic.com/css-tutorial/css-display.php

相关问题