Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS to stop text wrapping under image

I have the following markup:

<li id="CN2787">   <img class="fav_star" src="images/fav.png">   <span>Text, text and more text</span> </li> 

I want it so that if the text wraps, it doesn't go into the 'column' for the image. I know I can do it with a table (which I was doing) but this is not workable for this reason.

I've tried the following without success:

li span {width: 100px; margin-left: 20px} .fav_star {width: 20px} 

I also tried float: right.

Thanks.

EDIT: I want it to look like this:

IMG   Text starts here and keeps going... and       wrap starts here. 

Not like this:

IMG   Text starts here and keeps going... and  wrap starts in the space left for the image. 
like image 710
Nick Avatar asked Jul 10 '12 10:07

Nick


People also ask

How do I keep text from wrapping around an image in CSS?

You'll have to wrap your text in its own container. Since your <img> is floated to the left, you can use overflow: hidden on your newly-added container to achieve no wrapping of the text.

How do you stop text wrapping in CSS?

If you want to prevent the text from wrapping, you can apply white-space: nowrap; Notice in HTML code example at the top of this article, there are actually two line breaks, one before the line of text and one after, which allow the text to be on its own line (in the code).

How do I change the text wrap setting?

Go to File > Options >Advanced. In the Cut, copy, and paste section, change the setting under Insert/paste pictures as: to the text wrapping style you want. Select OK.


1 Answers

Very simple answer for this problem that seems to catch a lot of people:

<img src="url-to-image"> <p>Nullam id dolor id nibh ultricies vehicula ut id elit.</p>      img {         float: left;     }     p {         overflow: hidden;     } 

See example: http://jsfiddle.net/vandigroup/upKGe/132/

like image 91
Joe Conlin Avatar answered Sep 30 '22 11:09

Joe Conlin