html - 使用 CSS 的上-下-左-右-上-左-右-上-下内容流

标签 html css layout

我想要从上到下和从左到右组织的 css block 。

为了更好地解释这是一张图片,其中包含我到目前为止所获得的内容以及我希望使用 CSS 实现的内容:http://i.imgur.com/vowlqIZ.png

代码如下:

HTML:

<div id="container">
<div class="box" style="background-color: #000;">1</div>
<div class="box" style="background-color: #fff;">2</div>
<div class="box" style="background-color: #000;">3</div>
<div class="box" style="background-color: #fff;">4</div>
<div class="box" style="background-color: #000;">5</div>
<div class="box" style="background-color: #fff;">6</div>
<div class="box" style="background-color: #000;">7</div>
<div class="box" style="background-color: #fff;">8</div>
<div class="box" style="background-color: #000;">9</div>
</div

CSS:

#container {height: 200px; background-color: #2795b6;}
.box {color: red; display: block;height:50px;width:50px}

这是 JsFiddle:http://jsfiddle.net/ySG5Y

这是我正在尝试制作的水平无限滚动页面的一部分。现在您知道了,您可以更好地了解情况。

我希望有人能够以任何方式帮助我,并原谅我的知识不那么丰富。

谢谢

附言。现在我知道还有一些其他问题看起来像是重复的。我不知道,但我想将它集成到水平无限滚动中,所以我相信这可能是一个“原始问题”。

毕竟我不知道要描述这个所以那些在发布后显示。

最佳答案

我会再使用一个分组(每 4 个元素)

<div id="container">
    <div class="group">
        <div class="box">1</div>
        <div class="box">2</div>
        <div class="box">3</div>
        <div class="box">4</div>
    </div>
    <div class="group">
        <div class="box">5</div>
        <div class="box">6</div>
        <div class="box">7</div>
        <div class="box">8</div>
    </div>
    <div class="group">
        <div class="box">9</div>
    </div>
</div>

并使用

#container {
    height: 200px;
    background-color: #2795b6;
    font-size:0; /*to ignore whitespace due to inline-block of group elements*/
    white-space:nowrap; /*to avoid wrapping of groups once they fill their container*/
}
.group{
    position:relative;
    display:inline-block; /*make them stack horizontally*/
    width:50px;
    height:200px;
    font-size:16px;
    vertical-align:top;
}
/*for the even groups set the box elements to absolute and reverse order*/
.group:nth-child(even) .box{position:absolute;left:0;}
.group:nth-child(even) .box:nth-child(1){bottom:0;}
.group:nth-child(even) .box:nth-child(2){bottom:50px;}
.group:nth-child(even) .box:nth-child(3){bottom:100px;}
.group:nth-child(even) .box:nth-child(4){bottom:150px;}

.box {
    color: red;
    display: block;
    height:50px;
    width:50px;
    text-align:center;
    line-height:50px;
    background:black;
}
.box:nth-child(even) {background:white;}

演示在 http://codepen.io/gpetrioli/pen/qAIKd

这将产生
enter image description here

关于html - 使用 CSS 的上-下-左-右-上-左-右-上-下内容流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22233929/

相关文章:

html - 下拉菜单仍处于事件状态时菜单项的背景颜色

python - 如何将单行美化为多行?

html - 为什么高度动画显示 : none are isn't working?

javascript - 如何将我自己的 .css 和 .js 链接到 wordpress?

css - HTML 表格的 Firefox CSS 问题

css - 网格布局 : create CSS so Elements keep position when adjacent element gets resized

javascript - 如何托管 html 文件,如 css 和 javascript 文件

css - 无法使用 Vaadin 中的 scss 删除面板和页面顶部之间的边距

带有imageview的可点击布局的android选择器

javascript - 根据用户的浏览器调整屏幕大小