使用CSS居中多个内联块并将最后一行对齐到左侧

bog*_*src 9 html css html5 css3

我想水平居中几个内联块,但同时让它们在最后一行左对齐(见下文).

问题是我实现了这样的事情(http://jsfiddle.net/5JSAG/):

|        _____   _____        |
|       |     | |     |       |
|       |  1  | |  2  |       |
|       |_____| |_____|       |
|            _____            |
|           |     |           |
|           |  3  |           |
|           |_____|           |
Run Code Online (Sandbox Code Playgroud)

虽然我想要这样的东西:

|        _____   _____        |
|       |     | |     |       |
|       |  1  | |  2  |       |
|       |_____| |_____|       |
|        _____                |
|       |     |               |
|       |  3  |               |
|       |_____|               |
Run Code Online (Sandbox Code Playgroud)

您可以在http://jsfiddle.net/5JSAG/上看到一些示例HTML .

我已经尝试使用column-countcolumn-width,但我也想,这是行不通的,因为该块的顺序有所不同:

|        _____   _____        |
|       |     | |     |       |
|       |  1  | |  3  |       |
|       |_____| |_____|       |
|        _____                |
|       |     |               |
|       |  2  |               |
|       |_____|               |
Run Code Online (Sandbox Code Playgroud)

bog*_*src 3

找到了解决这个问题的一个非常简单的方法:只需在末尾添加一些填充 div,这些填充 div 与对齐的块具有相同的宽度。

http://jsfiddle.net/5JSAG/34/

HTML:

<div style="text-align:center">
    <div class="entry">1</div>
    <div class="entry">2</div>
    <div class="entry">3</div>
    <div class="entry">4</div>
    <div class="entry">5</div>
    <span class="fill"></span>
    <span class="fill"></span>
    <span class="fill"></span>
    <span class="fill"></span>
</div
Run Code Online (Sandbox Code Playgroud)

CSS:

.fill
{
    display:inline-block;
    width:100px;
    height:0px;
    line-height:0px;
    font-size:0px;
}

.entry 
{ 
    display:inline-block;
    margin-top:10px;
    width:100px;
    height:60px;
    padding-top:40px;
    border:1px solid red;
}
Run Code Online (Sandbox Code Playgroud)