Rumah  >  Artikel  >  hujung hadapan web  >  图片之间的间隙要怎么去掉?_html/css_WEB-ITnose

图片之间的间隙要怎么去掉?_html/css_WEB-ITnose

WBOY
WBOYasal
2016-06-24 12:03:241998semak imbas


<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>水平滚动图片</title><style>* {border:0; margin:0; padding:0;}</style></head><body><div id="scroller"><div id="images"><a href="http://www.baidu.com"><img     style="max-width:90%" height="150px" / alt="图片之间的间隙要怎么去掉?_html/css_WEB-ITnose" ></a><a href="http://www.baidu.com"><img     style="max-width:90%" height="150px" / alt="图片之间的间隙要怎么去掉?_html/css_WEB-ITnose" ></a><a href="http://www.baidu.com"><img     style="max-width:90%" height="150px" / alt="图片之间的间隙要怎么去掉?_html/css_WEB-ITnose" ></a><a href="http://www.baidu.com"><img     style="max-width:90%" height="150px" / alt="图片之间的间隙要怎么去掉?_html/css_WEB-ITnose" ></a><a href="http://www.baidu.com"><img     style="max-width:90%" height="150px" / alt="图片之间的间隙要怎么去掉?_html/css_WEB-ITnose" ></a></div><div><img     style="max-width:90%" height="150px" / alt="图片之间的间隙要怎么去掉?_html/css_WEB-ITnose" ><img     style="max-width:90%" height="150px" / alt="图片之间的间隙要怎么去掉?_html/css_WEB-ITnose" ></div></div></body></html>


回复讨论(解决方案)

你把代码换行去掉即可

<div id="images"><a href="http://www.baidu.com"><img     style="max-width:90%" height="150px" / alt="图片之间的间隙要怎么去掉?_html/css_WEB-ITnose" ></a><a href="http://www.baidu.com"><img     style="max-width:90%" height="150px" / alt="图片之间的间隙要怎么去掉?_html/css_WEB-ITnose" ></a><a href="http://www.baidu.com"><img     style="max-width:90%" height="150px" / alt="图片之间的间隙要怎么去掉?_html/css_WEB-ITnose" ></a><a href="http://www.baidu.com"><img     style="max-width:90%" height="150px" / alt="图片之间的间隙要怎么去掉?_html/css_WEB-ITnose" ></a><a href="http://www.baidu.com"><img     style="max-width:90%" height="150px" / alt="图片之间的间隙要怎么去掉?_html/css_WEB-ITnose" ></a></div>

或者直接设置浮动

img{float:left;}

试过了,去掉换行可行

神奇。。这是为啥呢

撸主啊 别人回答的答案可行就结贴给分吧。

你把代码换行去掉即可

<div id="images"><a href="http://www.baidu.com"><img     style="max-width:90%" height="150px" / alt="图片之间的间隙要怎么去掉?_html/css_WEB-ITnose" ></a><a href="http://www.baidu.com"><img     style="max-width:90%" height="150px" / alt="图片之间的间隙要怎么去掉?_html/css_WEB-ITnose" ></a><a href="http://www.baidu.com"><img     style="max-width:90%" height="150px" / alt="图片之间的间隙要怎么去掉?_html/css_WEB-ITnose" ></a><a href="http://www.baidu.com"><img     style="max-width:90%" height="150px" / alt="图片之间的间隙要怎么去掉?_html/css_WEB-ITnose" ></a><a href="http://www.baidu.com"><img     style="max-width:90%" height="150px" / alt="图片之间的间隙要怎么去掉?_html/css_WEB-ITnose" ></a></div>

或者直接设置浮动

img{float:left;}


为什么会这样,有没有解释?

所有具有display:inline-block特性的元素,都有一个特点,那就是代码换行会被解析成空白,没有为什么,这就是浏览器的渲染机制,基于这一点,代码如果清除换行可以解决,但是不希望所有的代码都挤在一起,那么你就可以设置浮动来解决,目的无非就是让块属性元素在同排内显示

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style>.box{width:100px;height:100px;background:#ccc; display:inline-block;}</style></head><body><div class="box"></div><div class="box"></div><div class="box"></div></body></html>

我建议你设一个img标签,把整站的img规范下来,这样整站的图片都没有间隙
代码如下:
img {
vertical-align: top;
         }

可以用表格来做 ,然后设置图片居左或则右(text-align:left),希望对你有用

给img加个style="display:block"试试

学习了

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn