Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I flow divs down the page instead of across it?

Tags:

css

css-float

If I have a collection of div elements, I can use CSS to have them flow across the page and overflow onto the next line.

Here's a simple example:

<html>
  <head>
    <title>Flowing Divs</title>
    <style type="text/css">
      .flow {
        float: left;
        margin: 4em 8em;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="flow">Div 1</div>
      <div class="flow">Div 2</div>
      <div class="flow">Div 3</div>
      <div class="flow">Div 4</div>
      <div class="flow">Div 5</div>
      <div class="flow">Div 6</div>
      <div class="flow">Div 7</div>
      <div class="flow">Div 8</div>
    </div>
  </body>
</html>

Is it possible to have the divs flow down the page instead of across it, so that they would flow down columns not along lines, but still occupy the same space as they would if they flowed across?

So for the example above, if they flowed into two lines of four divs, could I get the first column to contain Div1 and Div2 instead of Div1 and Div5?

like image 757
brabster Avatar asked Mar 17 '10 18:03

brabster


2 Answers

No, it is not possible. Easiest workaround is to make separate columns by adding wrapper-DIVs, and then adding content to each column. This could also be generated dynamically either with Javascript or serverside.

like image 79
Arve Systad Avatar answered Sep 26 '22 01:09

Arve Systad


Quickly threw this together.:

#column1 {float:left}  
#column2 {float:left}  
div div{height:100px;width:100px;border:1px solid}

<div id="column1">    
      <div>1</div>  
      <div>2</div>  
</div>  
<div id="column2">  
      <div>3</div>  
      <div>4</div>  
</div>
like image 42
Rob Avatar answered Sep 23 '22 01:09

Rob