Search code examples
htmlcsstabular

New table row when maximum width is reached


I have a table with images and I would like it to make a new row when 500px is filled with cells containing images which are each 250px wide. Like word-wrap for images. Can't make it work with max-width :/


Solution

  • Don't use a table. Tables are only meant to be used to display tabular data. Best to just use divs.

    .wrapper {
     width:500px;
     overflow:auto;
    }
    .wrapper img {
     width:250px;
     float:left;
    }
    
    
    <div class="wrapper">
    
        <img src="image.jpg" alt="" />
        <img src="image.jpg" alt="" />
        <img src="image.jpg" alt="" />
        <img src="image.jpg" alt="" />
    
    </div>