html - 元素之间的 CSS div 间隙

标签 html css

我发现太多关于这个主题的引用已经回答了,但我没有找到一个满意的答案。

按照案例:

enter image description here

我创建了一个具有预期行为的极简主义 fiddle :

enter image description here

@ See fidlle

如果有 3 个单元格,我希望每个 div 之间只有间隔。这可能仅使用 CSS?

[HTML]

<div class="cel-1-2">
   Max Size of Objects in Cache (Shared Memory)
    <div class="cel-1-2">
        <input type="text" placeholder="foo" />
    </div>
    <div class="cel-1-2">
        <select>
            <option value="foo">bar</option>
        </select>
    </div>
</div>
<div class="cel-1-2">
    foobar
</div>

[CSS]

[class*=cel-] {
   padding-right:10px;
   -moz-box-sizing: border-box; 
   -webkit-box-sizing: border-box;     
   box-sizing: border-box;
    background: blue;
}

.cel-1-2 {
    width: 50%;
    float: left;
}

input, select {
    width: 100%;
    float: left;
}

更清楚:

这就是我想要的

enter image description here

==>不是这个!

enter image description here

最佳答案

我不知道这里有什么问题。 这可以通过 CSS 轻松完成:

.parent {
   width: 100%;
   background: green;
    padding: 1em 0; 
    height: 500px;
}
.child {
    width: 30%;
    height: 200px;
    background: yellow;
    float: left;
}
.child + .child {
    margin-left: 5% /* 1 000 000 $ TIP */
}

现场演示:http://jsfiddle.net/hDqbk/

关于html - 元素之间的 CSS div 间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23762171/

相关文章:

html - hero div中的居中定位文本

javascript - 删除 html 自动对焦使用 javascript/jquery

html - 如何修改 bootstrap 3 导航栏响应尺寸

html - 实现 Bootstrap 无缝卡片列

html - 如何找到空的 html td 单元格并通过 php html css 更改背景颜色

javascript - 寻找光滑 slider 容器高度的问题

HTML:如何使水平导航栏具有下拉菜单?

html - Css Transition 淡入延迟淡出

html - margin-right 不适用于相对元素? (宽度 100%)

css - 从 css 模块中引用全局类名