简体   繁体   English

HTML 锚标记中超链接文本的内联换行

[英]Inline wrapping of hyperlink text in HTML anchor tag

I'm trying to find a way to allow really long text in an HTML link to wrap while containing the link in a compact rectangle.我正在尝试找到一种方法,允许 HTML 链接中的超长文本进行换行,同时将链接包含在一个紧凑的矩形中。

Essentially, I want this:本质上,我想要这个:

                      with a really, really
    Here is some text long link that wraps   and here is some more text.
                      around in a rectangle

Instead of:代替:

   Here is some text with a really, really long link that wraps
   around in a rectangle and here is some more text.

How can I do this?我怎样才能做到这一点?

You can do it like this in Firefox - it doesn't work in IE though :( 你可以在Firefox中这样做 - 它虽然在IE中不起作用:(

<p>Here is some text <a href="#">with a really, really long link that wraps</a> around in a rectangle and here is some more text.


<style type="text/css">

a {display: inline-block; max-width: 100px; vertical-align: middle;}

</style>

I know this is pretty old, but it was still one of the first search results that came up for me on the subject. 我知道这已经很老了,但它仍然是我在这个主题上提出的第一批搜索结果之一。 I found that using: 我发现使用:

white-space: pre-wrap;

forced the anchor to wrap the text around my width restrictions 强制锚点围绕我的宽度限制包装文本

I wound up having this issue because I was using bootstrap and it was by default setting this as one of it's styles 我结束了这个问题,因为我正在使用bootstrap,默认情况下将其设置为其中一种样式

.dropdown-menu > li > a{
    white-space: nowrap;
}

Which made kept the "word-break" and "width" css properties from actually solving the problem 这使得“word-break”和“width”css属性实际上解决了问题

So I first had to set that white-space property to "pre-wrap" instead 所以我首先必须将该空白属性设置为“预包装”

You can use display:inline-block; 你可以使用display:inline-block; css property on your link which will give you exactly the effect you desire (dont forget to set the width :). 链接上的css属性将为您提供您想要的效果(别忘了设置宽度:)。

display:inline-block is not supported in IE, but lucky for you someone has already done the hard work and come up with a workaround here . 显示:IE中不支持内联块,但幸运的是,有人已经完成了艰苦的工作并在此处提出了解决方法。

<p>Here is some text <a href="#">with a really, really long link that wraps</a> around in a rectangle and here is some more text.


<style type="text/css">

a {display: inline-block; max-width: 100px; vertical-align: middle;}

</style>

There are many ways:有很多方法:

display : inline-block;
display : inline;
white-space: pre-wrap;
white-spa s: nowrap;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM