3

I am new in CSS so have a simple question.

here is my script =>

<!DOCTYPE html>
 <html>
 <head>
 <title>Default</title>
 <meta charset="UTF-8">
 <style type="text/css">
    body,div,html,img
    {
        margin: 0;
        padding: 0;
        border: 0;
    }
  </style>
  </head>
  <body>
      <div>
          <img src="/project/pics/5.jpg" width="240" height="200">
          <img src="/project/pics/10.jpg" width="240" height="200">
          <img src="/project/pics/10.jpg" width="240" height="200">
      </div>
   </body>
 </html>

So my question is that , despite of CSS reset between images are spaces, which of course cause some problems after styling layout, so anyone knows how to solve , how to reset CSS that there were not any spaces between images, Thanks ...

I guessed lol, it is really very simple , just it must be written in one line , otherwise it must be declared font-size: 0;

Thanks all :))

falsarella
  • 12,217
  • 9
  • 69
  • 115
nanobash
  • 5,419
  • 7
  • 38
  • 56

4 Answers4

7

The reason that happens is that the browser parses the linebreaks between images as spaces. Images are inline elements, and will have a literal space between them when a whitespace (or a linebreak) is used.

To eliminate the problem, either float: left; on the images, or simply eliminate the line breaks (as in, put them all on the same line, with no spaces between the tags).
Another solution is to set font-size: 0; on the parent, and then font-size: 16px; on the elements themselves.

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
1

For a full CSS reset use this instead

*{
    margin: 0;
    padding: 0;
    border: 0;
}

Then float the image elements

img{
   float: left;
}
Malitta N
  • 3,384
  • 22
  • 30
1

Try floating them left. See this example

jacktheripper
  • 13,953
  • 12
  • 57
  • 93
  • How I know it is possible to solve this problem without mentioned, but I can not get it what I have missed in CSS script – nanobash Feb 29 '12 at 19:22
1

You can put the images contiguous:

  <div>
      <img src="/project/pics/5.jpg" width="240" height="200" /><img
           src="/project/pics/10.jpg" width="240" height="200" /><img
           src="/project/pics/10.jpg" width="240" height="200" />
  </div>

Or, you can do something (that I don't consider a css reset) to handle:

falsarella
  • 12,217
  • 9
  • 69
  • 115