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

php中文网
发布: 2016-06-24 12:03:24
原创
2276人浏览过


<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>
登录后复制

美间AI
美间AI

美间AI:让设计更简单

美间AI 45
查看详情 美间AI

回复讨论(解决方案)

你把代码换行去掉即可

<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"试试

学习了

HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号