简体   繁体   English

CSS的顶部-底部-左侧-顶部-左侧-右侧-顶部-底部内容流

[英]Top-Bottom-Left-Right-Top-Left-Right-Top-Bottom content flow with CSS

I'd like to have css blocks that organize from top to bottom and from left to right. 我想让css块从上到下,从左到右组织。

To better explain this is an image with what I've got 'till now and what I'd like to achieve with CSS: 为了更好地说明这是一张我现在要了解的图像以及想要使用CSS实现的图像: http://i.imgur.com/vowlqIZ.png

Here is the code: 这是代码:

HTML: 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

The CSS: CSS:

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

And here is the JsFiddle: http://jsfiddle.net/ySG5Y 这是JsFiddle: http : //jsfiddle.net/ySG5Y

This is part of a horizontal infinite scrolling page I'm trying to make. 这是我要制作的水平无限滚动页面的一部分。 Now that you know you can better understand the situation. 现在您知道了,您可以更好地了解情况。

I hope someone is able to help me in any way, and forgive me for my not-so-great knowledge. 我希望有人能够以任何方式帮助我,并原谅我不那么丰富的知识。

Thanks 谢谢

Ps. PS。 Now I know that there are some other questions which may seem like a duplicate. 现在我知道还有其他一些问题,看起来似乎是重复的。 I don't know but I'd like to integrate this in horizontal infinite scrolling so I believe that this may be a "original question". 我不知道,但是我想将其整合到水平无限滚动中,因此我相信这可能是一个“原始问题”。

After all I had no idea about describing this so those showed after the publishing. 毕竟,我不知道要对此进行描述,所以这些内容在发布后就会出现。

I would use one more grouping ( per 4 elements ) 我会再使用一个分组( 每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>

and use 和使用

#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;}

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

This will produce 这将产生
在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM