html - 基本 CSS 定位(适合容器中的 child )

标签 html css position

非常基本的 CSS 问题。鉴于 http://jsfiddle.net/danwoods/65X7X/ 中显示的代码为什么子 div(彩色 block )不适合容器元素?

来自 fiddle 的 CSS

.container {
    width: 360px;
    height: 50px;
    border: 1px solid black;
}
.container div {
    width: 120px;
    height: 100%;
    display: inline-block;
}
.one {
    background: blue;
}
.two {
    background: green;
}
.three {
    background: red;
}

提前致谢,

最佳答案

因为行内元素对空格敏感。您可以删除它们,使 HTML 看起来像:

<div class="container">
    <div class="one"></div><div class="two"></div><div class="three"></div>
</div>

jsFiddle example

或者让 div 向左浮动:

.one,.two,.three {
    float:left;
}

jsFiddle example

或者使用 HTML 注释来吃掉空白:

<div class="container">
    <div class="one"></div><!--
    --><div class="two"></div><!--
    --><div class="three"></div>
</div>

jsFiddle example

关于html - 基本 CSS 定位(适合容器中的 child ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21315826/

相关文章:

html - 视口(viewport)中带有 WOW.js 的元素动画

php - 未选择过滤器选项时显示所有记录

html - 图片/div 太大

javascript - 如何避免 Angular 中的元素重叠

c# - 如何确保每个 DIV 独立出现而不重叠

html - 在每行文本的开头和结尾添加填充

html - 相对于 DIV 的固定容器——这可能吗?

javascript - Tablesorter:仅允许外部过滤器搜索子行

html - 将 div 置于文本之上

html - z-index 和 css 权威指南 图 10-55