移除HTML/CSS中图片标签之间的水平间距

4
我刚刚在练习HTML和CSS时遇到了一个烦人的问题。我想知道那个水平间隙是什么,并且如何去除它?
提前致谢。 enter image description here
<!DOCTYPE html>
<html lang="en">
   <head>
      <title>Practice</title>
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
      <meta content="utf-8" http-equiv="encoding" />
      <style>
         html,body
         {
         margin:0; padding:0; height:100%;
         }
      </style>
   </head>
   <body>
      <script src="./js/jQuery.js"></script>

      <img id="sample-img" src="Green-Nature-wallpaper.jpg" style="margin:0; padding:0;"></img>
      <img id="sample-img2" src="Green-Nature-wallpaper.jpg" style="margin:0; padding:0;"></img>
      <script>
         $( document ).ready(function () {
            $("#sample-img").width($(window).width());
            $("#sample-img").height(0.6*$(window).height());
            $("#sample-img2").width($(window).width());
            $("#sample-img2").height(0.6*$(window).height());
         });
         $(window).resize(function() {
            $("#sample-img").width($(window).width());
            $("#sample-img").height(0.6*$(window).height());
            $("#sample-img2").width($(window).width());
            $("#sample-img2").height(0.6*$(window).height());
         });
      </script> 
   </body>
</html>

当您在浏览器中进行调试时,您看到了什么? - ElGavilan
@ElGavilan 什么也没有,空的... - Node.JS
把图片之间的空白变成块状显示。 - Daniel A. White
你确定实际图像本身没有包含额外的边距吗? - tckmn
2个回答

4
你尝试将图像的边距和内边距设为0了吗?
<style>
    img {
        position:relative;
        display:block;
        margin:0;
        padding:0;
    }
</style>

它运行成功了,谢谢。 - Node.JS
1
这个方法可以运行,但不一定是最佳答案。它将图像的默认内联样式更改为块级元素。这可能没问题,但根据上下文可能会导致不良影响。 - Rob
1
这取决于页面是否使用其他图像。如果是,他可以简单地为要显示为块的图像分配一个类,并将其他图像保留为其默认CSS。 - Tai Kwangi Chicken

0

图像是内联内容,就像单词或单个字符一样。图像与放置字符的基线对齐。在图像CSS中添加vertical-align:bottom。图像是内联元素,类似于文本放置,您所看到的是保留给文字字体下行字母(如字母“g”的下部弯曲)的间隙。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接