Images side by side without any space between them

后端 未结 5 1957
面向向阳花
面向向阳花 2020-12-17 11:03

I have a grid of images with space between them. How do I remove this space?

I have already tried setting the padding and margin of the ima

相关标签:
5条回答
  • 2020-12-17 11:22

    add font-size:0px to the div, then you can continue keeping the img elements on separate code lines

    0 讨论(0)
  • 2020-12-17 11:23

    If you use float: left on the images, and separate each row with a breaker with a clear: both then there should be no spaces between the images.

    0 讨论(0)
  • 2020-12-17 11:26

    Make sure you don't have any spaces in your html markup. So change:

    <img src="" alt="" /> <img src="" alt="" />
    

    to

    <img src="" alt="" /><img src="" alt="" />
    

    Sometimes spaces can hide at the end of new lines too, so be sure to check the end of lines if your html looks like

    <img src="" alt="" /> 
    <img src="" alt="" />
    

    Edit

    Instead of writing: <img src="imgs/img8.jpg" style="margin: 0; width: 300; height: 300;" /> 87 times, just put this in your css file:

    div img { margin: 0;
        width: 300px;
        height: 300px;
    }
    

    and then you can simply make your images <img src="imgs/img8.jpg" alt="img8" />

    0 讨论(0)
  • 2020-12-17 11:28

    The parameters you need to zero are padding, border and margin. On the images themselves and any container in between.

    0 讨论(0)
  • 2020-12-17 11:30

    Try putting two images on the same line like:

    <img src="imgs/img0.jpg" style="margin: 0; width: 300; height: 300;" /><img src="imgs/img1.jpg" style="margin: 0; width: 300; height: 300;" />
    

    and see if that changes anything. I also suggest you follow the advice about using CSS to simplify all of the image styles. Because right now, you'd have to manually change every value by hand if you wanted to change the image sizes.

    Unfortunately, HTML has some silly white-space problems sometimes.

    0 讨论(0)
提交回复
热议问题