代码之家  ›  专栏  ›  技术社区  ›  Steve

中心浮动可变div数

  •  1
  • Steve  · 技术社区  · 14 年前

    .block-gray { background: url('grey.gif'); width: 15px; height: 3px; }
    

    alt text

    .block-yellow { background: url('yellow.gif'); width: 15px; height: 3px; } 
    

    alt text


    我想做的是使用上面的一个类定义一个可变数量的div,并让它们水平堆叠,并集中在一个更大的容器中。

    所以,如果我定义了3个这样的块:

    <div>
       <!-- The # of these is variable, and not necessarily fixed at 3 -->
       <div class="block-yellow"></div>
       <div class="block-yellow"></div>
       <div class="block-grey"></div>
    <div>
    

    | alt text alt text alt text |

    谢谢。

    2 回复  |  直到 14 年前
        1
  •  5
  •   Bobby Jack    14 年前
    .container    { text-align: center; }
    .block-yellow { display: inline-block; }
    

    您可能需要重置文本对齐:

    .block-yellow { text-align: left; }
    
        2
  •  0
  •   jargalan    14 年前