html - 为什么这2个div之间有差距

标签 html css

http://jsfiddle.net/D9gnP/110/

两列之间有一个小间隙。我什么都没设置,那个间隙从哪里来?

这与这些元素上的 display:inline-block 有什么关系吗?他们有内部 margin 吗?

  <div id="wrapper" style="margin:auto;background-color:yellow;height:100%;">
      <div style="width:50px;height:100%;">
        <div class="fluid-column" style="height:80%; background-color:green;">
          <div style="background-color:#ff99cc; height:25%;">1</div>
          <div style="background-color:#ff33cc; height:50%;">2</div>
          <div style="background-color:#ff66cc; height:25%;">3</div>
        </div>
        <div class="fix-column" style="height:20%; background-color:violet">
          <div style="background-color: orange;height:50%;">Total</div>
          <div style="background-color: blue;height:50%;">Test</div>
        </div>
      </div>
    </div>

body, html {
    width:100%;
    height:100%;
    margin:0;
    padding:0;
}
div {
    text-align:center;
    text-indent:-0.5em;;
}
div span {
    display:inline-block;
    height:100%;
    vertical-align:middle;
    width:0;
}

最佳答案

由于元素是内联的,因此它们被视为内联,包括因空白而产生的空格。

尝试删除元素之间的空白(包括新行)。

<div>Content</div><!-- this white space/new line causes the gap -->
<div>Content</div>

<div>Content</div><div>Content</div><!-- no new line/white space, no gap-->

你也可以将这个添加到容器元素中进行调整:

word-spacing: 0;

或者你可以只使用 float 元素:)

看这里,如果你只是删除空格,就会按预期工作:http://jsfiddle.net/D9gnP/121/

关于html - 为什么这2个div之间有差距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17145743/

相关文章:

html - CSS 绘制带有阴影的形状

javascript - HTML 谷歌地图定制

html - 如何防止 Bootstrap Navbar 将品牌堆叠在菜单顶部?

html - 相同文本的不同字体大小(一部分文本的字体大小为 "X",另一部分的字体大小为 "Y")

javascript - 如何使用 JavaScript 更改当前页面导航按钮/链接的背景颜色?

jquery - 使用 jquery show/hide 不会将 css 保留在 div 中

html - WP Members - Wordpress - 自定义注册页面

javascript - 动态设置 `grid-template-areas` 的问题

html - 将 img 与另一个 div 完全重叠

html - 被 clip-path 隐藏的元素仍然会增加页面长度