Prevent single word from wrapping around float in css/html

心不动则不痛 提交于 2019-12-04 08:38:49

Preventing single-word wrapping is easy: just use a no-break space between the last two words, instead of a normal space (e.g., nostrud exercitation).

However, I’m afraid this would not solve the real problem. In the sample case, there would be a two-word wrap, leaving the last but one line short. And if text gets larger, the two words would stick together even when there is no need for that.

I’m afraid that problem would need some nontrivial JavaScript code that analyzes, after initial formatting, the height of the text block as compared with the height of the image and changes styling by some criteria.

Just add padding-bottom: 1px; to img

Demo

img {
    float:left;
    margin:10px;
    width:100px;
    height:100px;
    padding-bottom: 1px;
}

You can also use right and left columns, yeah I've certainly used an inline style but if you want to go for this approach than make a class for clear and get rid of the inline style

Demo 2

user1010892

Sorry - not a definite answer but I asked the same question a while back. One of the answers I received there was promising (using JS) but so far I haven't been able to work it out. My question also uses an image to illustrate the issue which might be helpful.

I come across this issue all the time in responsive layouts using a CMS

Awkward line wrap around image

The solution is to increase the .wrapper class width a little.

here is the .wrapper class:

.wrapper {
        width:330px;
        margin-bottom:20px;
    }

http://jsfiddle.net/wdPCp/4/

Add overflow: hidden to .text if you don't want the text to wrap under the float.

http://jsfiddle.net/wdPCp/6/

Look through the different display styles. Table display (not the tags) do not under-wrap floated elements.

.text{
  display:table;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!