Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML - non-breaking space between text and image

Tags:

html

So I have a menu where each (multiline) item has an image rightarrow.png right after the last word of the menu item. The problem is sometimes this arrow goes into a newline by itself, and I want to stop that from happening. I tried

Blah blah&nbsp;<img src="rightarrow.png" />

but still in some cases it looks like

Blah blah
>

It's driving me crazy.

like image 379
L84 Avatar asked Dec 11 '12 06:12

L84


People also ask

How do you insert a nonbreaking space in HTML?

HTML Non-Breaking Space (&nbsp;) The simplest way to add a space in HTML (besides hitting the spacebar) is with the non-breaking space entity, written as &nbsp; or &#160;.

How do you put space between images and text in HTML?

Usually, it is preferable to have a little space between the image and the surrounding text. In HTML, you provide this space by using the vspace and hspace attributes within the img element. In CSS, to align an element with no text wrap, apply the text-align property to a block-level element that contains the image.

How do you insert a nonbreaking space?

Place your cursor where the nonbreaking space should be inserted. Alternately, if a regular space already appears where the nonbreaking space should be inserted, select the regular space (see figure 1). 2. Select Ctrl + Shift + Space on your keyboard to insert the nonbreaking space.


3 Answers

Put all your text in an element, then put the image in another wrapper. Add white-space:nowrap to their parent.

like image 195
Asad Saeeduddin Avatar answered Oct 06 '22 12:10

Asad Saeeduddin


This is the method that works across browsing situations:

Blah <nobr>blah <img src="rightarrow.png" /></nobr>

The nobr tag never got to HTML specs, for some odd reason, but this does not prevent it from working. If you just have to comply with the specs, use clumsier CSS instead:

Blah <span style="white-space: nowrap">blah <img src="rightarrow.png" /></span>
like image 26
Jukka K. Korpela Avatar answered Oct 06 '22 10:10

Jukka K. Korpela


Check this BIN. I made this after assuming this is what you need.

HTML

  <ul>
<li><p>Menu 1</p> <img src="http://www.eurotunnel.com/uploadedImages/commercial/back-steps-icon-arrow.png" align="right"/></li>
<li><p>Menu 2</p> <img src="http://www.eurotunnel.com/uploadedImages/commercial/back-steps-icon-arrow.png" align="right"/></li>
<li><p>Menu 3</p> <img src="http://www.eurotunnel.com/uploadedImages/commercial/back-steps-icon-arrow.png" align="right"/></li>
<li><p>Menu 4</p> <img src="http://www.eurotunnel.com/uploadedImages/commercial/back-steps-icon-arrow.png" align="right"/></li>
  </ul>

Css

ul{ list-style-type:none;}
ul li{ float:left; padding:10px; width:100px;}
img{ width:20px;height:20px; float:left;}
p{ float:left; margin:0px; }

Check here for more details

like image 1
Vivek Dragon Avatar answered Oct 06 '22 12:10

Vivek Dragon