Leaf
Leaf

Reputation: 553

Carry-over table to new row

I have a table each cell of which contains other table. What i wonder to know is how to make table start new row when there is no space on screen for new column. Here is my show.html.erb:

<table border="1">
    <tr>
        <% @photos.each do |photo| %> 
            <td>
                <table border="1">
                    <tr>
                        <td><%= photo.author %></td>
                    </tr>
                    <tr>
                        <td><%= photo.title %></td>
                    </tr>
                    <tr>    
                        <td><%= photo.link %></td>
                    </tr>    
                </table>
            </td>    
        <%end%>
    </tr>    
</table>            

Upvotes: 0

Views: 111

Answers (1)

Emile Swarts
Emile Swarts

Reputation: 103

There are many different screen resolutions, and setting it to work by displaying x number of columns, will look different for other user. CSS may be better (and simpler) at solving this problem than ruby. Create left floated divs, which will automatically drop to a new row when the row runs out of space.

.gallery_column {
  float: left;
  width: 150px;
  border: 1px solid;
}

<div class='gallery_column'>
  <% @photos.each do |photo| %> 
        <table border="1">
            <tr>
                <td><%= photo.author %></td>
            </tr>
            <tr>
                <td><%= photo.title %></td>
            </tr>
            <tr>    
                <td><%= photo.link %></td>
            </tr>    
        </table>
  <%end%>
</div>

Upvotes: 1

Related Questions