How can you align elements like a poster board using CSS?

Looking to create a unique box layout inspired by this posterboard design:

Currently, my boxes have fixed widths and resizable heights based on their content. However, I'm struggling to get them to stack horizontally like the example above. Any ideas on how to achieve this effect?

Here's what I have tried so far: http://jsfiddle.net/SEe42/1/ I attempted using the max-height attribute to push the boxes to the next column, but they continue to stack vertically.

html:

<!doctype html>
<body>
    <div class="container">
        <div class="panel">
            voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo ino
        </div>
        <div class="panel">
            voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque i
        </div>
        <div class="panel">
            voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo  accusantium doloremque laudantium, totam 
        </div>
    </div>
</body>

css:

.container {
    width: 500px;
    max-height: 300px;
}
.panel {     
    display: block;
    position: relative;
    width: 100px;
    margin: 10px 5px 10px 5px;
    border-style: solid;    
}

Answer №1

Check out the Demo

This is a responsive CSS-only solution that utilizes the CSS column properties.

Here is the HTML code:

<div class="container">
    <div class="panel">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
    <div class="panel">Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</div>
    <div class="panel">Vestibulum sodales nisi quis quam varius, nec tincidunt velit placerat.</div>
    <div class="panel">Fusce maximus nisl vitae magna efficitur, non posuere metus laoreet.</div>
    <div class="panel">In hac habitasse platea dictumst. Sed vel semper ligula.</div>
</div>

And here is the CSS code:

body {
    font: 1em/1.67 'Open Sans', Arial, sans-serif;
    margin: 0;
    background: #e9e9e9;
}

.container {
    margin: 1.5em;
    padding: 0;
    -moz-column-gap: 1.5em;
    -webkit-column-gap: 1.5em;
    column-gap: 1.5em;
    font-size: .85em;
}

.panel {
    display: inline-block;
    background: #fff;
    padding: 1em;
    margin: 0 0 1.5em;
    width: 100%;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-shadow: 2px 2px 4px 0 #ccc;
}

@media only screen and (min-width: 400px) {
    .container {
        -moz-column-count: 2;
        -webkit-column-count: 2;
        column-count: 2;
    }
}

@media only screen and (min-width: 700px) {
    .container {
        -moz-column-count: 3;
        -webkit-column-count: 3;
        column-count: 3;
    }
}

@media only screen and (min-width: 900px) {
    .container {
        -moz-column-count: 4;
        -webkit-column-count: 4;
        column-count: 4;
    }
}

@media only screen and (min-width: 1100px) {
    .container {
        -moz-column-count: 5;
        -webkit-column-count: 5;
        column-count: 5;
    }
}

Answer №2

Make sure to include float: left in your .panel class for proper alignment.

To see a demonstration, please click here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The custom bullet points are not appearing correctly

I've been attempting to design a custom bullet list, but it doesn't look quite right as I had hoped. The issue is that the spacing appears too close, you can see an example HERE Any suggestions would be greatly appreciated. Thank you ...

Encountering an error message stating "Unable to read property 'map' of undefined while attempting to create drag and drop cards

I have incorporated the library available at: https://github.com/clauderic/react-sortable-hoc The desired effect that I am aiming for can be seen in this example: https://i.stack.imgur.com/WGQfT.jpg You can view a demo of my implementation here: https:// ...

The functionality of broadcasting events and using the 'on' method seems to be malfunctioning

I'm facing an issue where I am attempting to send an event from one controller to another and listen for it, but the data is not being displayed on the DOM. Interestingly, there are no errors present. When displaying regular $scope variables from both ...

the absence of any content being shown when using v-else

I'm currently delving into Vue.js and stumbled upon an unusual behavior that I couldn't find any information about on the Internet. For some reason, the DIV with v-else isn't rendering any content that I place inside it. I tried to underst ...

Once an ajax request is made, scripts cease to function correctly

There is a dynamic table on a webpage that I update using ajax. The table contains checkboxes and there are scripts that utilize the checkboxes for certain functionalities, such as toggling the check/uncheck status of all checkboxes when a "Check all / Unc ...

What is the solution to preventing Angular 1.3 ngMessages from affecting the size of my form?

Hey there, I'm diving into front-end design for the first time. My issue is with a form that I want to use ng-messages for validation error messages. Currently, my form's size changes depending on whether there are errors displayed or not, and it ...

Is it possible to determine the outcome of a JavaScript function using Python?

I am currently in the process of creating a web crawler. Extracting links from HTML is simple, but finding links that are generated by JavaScript proves to be more challenging for me. Is there a way to access the JavaScript output in order to determine w ...

Utilize Javascript or Jquery to intercept and handle both GET and POST requests

Is there a method to effectively intercept and capture both GET and POST requests as they are sent from the browser to the server? In my web application, full page refreshes occur after each request is submitted, however, some pages experience delays in r ...

If a quote character is detected in a string, color the line red

My goal is to highlight each line from a string in red if it contains the ">" character. I am applying this logic to a database query result, and while it's successful, I'm encountering an issue where an HTML line break is inserted after each ...

The color of the element remains unchanged even when hovering the cursor over it

Below is an example of HTML code: <h1 class="one">Hello</h1> Here is the corresponding CSS style sheet applied to it: h1:hover { color: red; } h1.one { color: blue; } When this code runs, the h1 element should turn blue. Ho ...

javascript trigger next input upon meeting condition

Currently, I am utilizing the jQuery liveform validation plugin to validate the input field based on a condition. The following code is used to automatically move to the next input field once the maximum input limit is reached. window.onload=function(){ ...

What is the best way to eliminate excess space on the right side in Bootstrap 4 while in mobile view?

I'm struggling to understand why this layout is not responsive on mobile devices, triggering a bottom scroll bar at around 616px. I'm looking for a solution to hide the scroll bar at least until 414px for iPhones and other smartphones. I've ...

Parsing through JSON information retrieved from an API

I am working with an API that provides data in two arrays, each containing a category. I need help iterating through and displaying these categories, specifically the ones for Arts and Entertainment. Any assistance would be greatly appreciated. Thank you ...

bringing in a nested object from an API

Check out this link: http://jsonplaceholder.typicode.com/users. In the address object, there is a geo object that I attempted to import using this method, but it doesn't display anything on the webpage. {identity.address && identity.geo & ...

Using Selenium and PhantomJS for web scraping to retrieve information on product details

As a beginner in web scraping with Python, I am currently working on extracting product details from a webpage using Selenium and PhantomJS. However, I am facing a challenge as the page does not display the rendered HTML when I try to access it using "driv ...

What sets apart using 'self.fn.apply(self, message)' from 'self.fn(message)', and what are the advantages of using the former method?

Whenever I come across code that looks like thisnewPromise.promiseDispatch.apply(newPromise, message), I can't help but wonder why they didn't simply use newPromise.promiseDispathch(message) ...

Querying the field's object type in MongoDB

My database contains records with a field that has different data types in each record. I would like to query only for the records where this field contains strings. Is there a way to search for specific data types in this field? {"field1":ObjectId("53de" ...

Positioning a row at the bottom of a container in Bootstrap 4

What is the best way to position a bootstrap row at the bottom of a container? Here is an example: HTML <main class="bd-masthead container-fluid" id="" role="main" style="padding-top:5rem;"> <div class="row"> <div class="col"> ...

Transform a loaded image into canvas

I have encountered a challenge while working on a plugin where I need to convert an Image into Canvas and store it as data URL. The function currently triggers on the 'load' event, but how can I achieve this conversion for an image that is alread ...

Generating a compilation from an array in React JS

Having trouble creating an array to store my category links and display them on my website. However, I'm not seeing anything in my DOM. Any assistance would be greatly appreciated :) import React from "react"; import { SidebarCategory } from './ ...