3

如何在每组两个列表元素之后插入换行符?它不一定需要是 HTML <br />,而只是将接下来的两个元素移动到下一行的东西。尝试在这里完全使用 CSS/3(通过 jQuery)。

HTML:

<div id="headline_gallery">
    <ul>
        <li><img src="images/picture1.png" alt="picture1" /></li>
        <li><img src="images/picture2.png" alt="picture2" /></li>
        <li><img src="images/picture3.png" alt="picture3" /></li>
        <li><img src="images/picture4.png" alt="picture4" /></li>
    </ul>
</div>

CSS:

#headline_gallery li:nth-child(4n),#headline_gallery  li:nth-child(4n-1) {
    background:red;
    display:inline;
}

#headline_gallery li:nth-child(4n-2),#headline_gallery  li:nth-child(4n-3) {
    background:blue;
display:inline;
}
4

2 回答 2

8

我会使用好的旧浮点数和第 n 个子选择器

http://jsfiddle.net/QCcca/

li {
    float: left;
}
li:nth-child(odd) {
    clear: left;
}
于 2013-05-15T09:30:46.017 回答
2

Float the LIs left and then clear after every second:

#headline_gallery li {
    float: left;
}
#headline_gallery li:nth-child(2n + 1) {
    clear: left;
}

Demo

于 2013-05-15T09:25:14.717 回答