Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

space between <img> tags

Tags:

html

if i use this code (with spaces between the two tags):

<img src="....." style="border:0px;margin:0px" />
<img src="....." style="border:0px;margin:0px" />

there are 4 pixels between images. if I use this:

<img src="....." style="border:0px;margin:0px" /><img src="...." style="border:0px;margin:0px" />

the space between images disappear, on all browsers!

Why????????

like image 475
Omega Avatar asked Mar 07 '11 14:03

Omega


People also ask

How do I put space between images 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.

Can we give spaces between tags?

The <&nbsp> tag creates a space that does not break into a new line. Two words that are separated by a non-breaking space always appear on the same line. You can also add space around text using Cascading Style Sheets (CSS).

How do I add a space between tags?

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;. Multiple adjacent non-breaking spaces won't be collapsed by the browser, letting you “force” several visible spaces between words or other page elements.


2 Answers

That's because white space is significant for inline elements. You can always float your images if you want to have them line up.

Edit: As requested, here is a simple example:

/* This is used to "clear" the floated elements */
.images { overflow: hidden; width: 100% }

/* float the elements so that white space does not matter */
.images img { float: left; }
<div class="images">
    <img src="http://dummyimage.com/150x100/000/fff&text=first+image" alt="first image" />
    <img src="http://dummyimage.com/150x100/6aa8de/fff&text=second+image" alt="second image" />
    <img src="http://dummyimage.com/150x100/ff6500/fff&text=third+image" alt="third image" />
</div>
like image 110
wsanville Avatar answered Oct 22 '22 04:10

wsanville


<img src="http://www.nataliedee.com/111908/whatever-dude-whatever.jpg" style="border:0px;margin:0px;float:left;width:200px;" />
<img src="http://www.nataliedee.com/111908/whatever-dude-whatever.jpg" style="border:0px;margin:0px;clear:both;width:200px;" />

http://jsfiddle.net/JNWc7/

like image 7
Michael Avatar answered Oct 22 '22 03:10

Michael