html - `display:inline-block` 元素上的奇怪边距

标签 html css

我在一行中有 6 个 DIVdisplay:inline-block。但是他们之间有一个奇怪的空白,我该如何摆脱呢?它们应该排成一行放入容器中。

fiddle :http://jsfiddle.net/y7L7q/

HTML:

<div id="container">
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
</div>

CSS:

#container{
    width:300px;
    border:1px solid black;
}
.box{
    display:inline-block;
    height:50px;
    width:50px;
    background-color:black;
    margin:0;
    padding:0;
}

最佳答案

font-size:0;。像这样:

#container{
    width:300px;
    border:1px solid black;
    font-size:0;
}

检查这个http://jsfiddle.net/y7L7q/1/

这样写你的标记:

<div id="container">
    <div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div>
</div>

检查这个http://jsfiddle.net/y7L7q/2/

关于html - `display:inline-block` 元素上的奇怪边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9664321/

相关文章:

html - CSS - 文本上的图标

html - 当我减少标签上的行高时,单词会相互重叠

java - 如何使用 xpath 从特定站点获取值并将其存储在数组中? (安卓)

python - 已编辑 : How do I create a "Nested Loop" that returns an item to the original list in Python and Scrapy

html - HTML 中特殊的不存在元素空间

css - 将鼠标悬停在一级菜单项上时,使二级纯 CSS 下拉菜单出现

javascript - 猫头鹰轮播2导航

html - 垂直对齐列出元素

html - 如何将字体 "Balzano"设置为我网站上 <p></p> 中包含的文本?

html - div 内 100% 宽度的输入与 div 重叠