开发者

wrapping a link with a div element & disable the divs line break

开发者 https://www.devze.com 2023-01-20 17:49 出处:网络
I wrapped a link with a div-element $("a[href$=\'name开发者_运维百科\']").wrap("<div />");

I wrapped a link with a div-element

$("a[href$='name开发者_运维百科']").wrap("<div />");

The div-element causes line breaks. To prevent this behaviour I'd like to style my div-element with style="white-space: nowrap;".

I tried

$("a[href$='name']").wrap("<div style='white-space: nowrap;'></div>");

For some reason it doesn't work. There is no error shown. The line break however is still active.

What's wrong with my snippet?

Thanks for your help.


When you wrap an element inside a div it will surely break in line since the div element will consume the whole line. Why not wrap it with span instead if you want to maintain the continuity of the paragraph or sentence or phrase?


If for any reason the element NEEDS to be a div, and cannot be a span. You could give the div:

display: inline-block;

to get similar behaviour.

0

精彩评论

暂无评论...
验证码 换一张
取 消