Arranging divs using inline-block display. How to adjust the heights consecutively?

After much searching and attempting, I am still unable to achieve a simple task. My goal is to apply display inline-block to some divs while aligning them in a row, similar to the image below:

https://i.sstatic.net/iLhLS.png

The issue arises when number 4 and 5 are positioned after 1 with display inline-block:

https://i.sstatic.net/trftf.png

Any suggestions on how to resolve this?

.post-it {
  background-color: #F00;
  height: 140px;
  padding: 1em;
  width: 150px;
  display: inline-block;
  margin: 0 1.3em 1.5em 0;
  box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.50);
}

 .title {
   font-size: 2em;
   font-weight: bold;
   line-height: 1em;
   margin-bottom: .2em;
}

#today {
  height: 300px;
}
<div>
  <div class="post-it" id="today">
    <header>
      <div class="title">
        Day 25
      </div>
      <hr>
    </header>
  </div>
  <div class="post-it">
    <header>
      <div class="title">
        Day 26
      </div>
      <hr>
    </header>
  </div>
  <div class="post-it">
    <header>
      <div class="title">
        Day 27
      </div>
      <hr>
    </header>
  </div>
  <div class="post-it">
    <header>
      <div class="title">
        Day 28
      </div>
      <hr>
    </header>
  </div>
  <div class="post-it">
    <header>
      <div class="title">
        Day 29
      </div>
      <hr>
    </header>
  </div>
</div>

Answer №1

To improve the layout, consider setting a fixed width on the outer div, named #calendar, and then adding the property float: left to your .post-it class. This adjustment should help with the display!

.post-it {
  background-color: #F00;
  height: 140px;
  padding: 1em;
  width: 150px;
  display: inline-block;
  margin: 0 1.3em 1.5em 0;
 float: left;
  box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.50);
}

 .title {
   font-size: 2em;
   font-weight: bold;
   line-height: 1em;
   margin-bottom: .2em;
}

#today {
  height: 300px;
}
#calendar {
  width: 800px;
}
<div id="calendar">
  <div class="post-it" id="today">
    <header>
      <div class="title">
        Day 25
      </div>
      <hr>
    </header>
  </div>
  <div class="post-it">
    <header>
      <div class="title">
        Day 26
      </div>
      <hr>
    </header>
  </div>
  <div class="post-it">
    <header>
      <div class="title">
        Day 27
      </div>
      <hr>
    </header>
  </div>
  <div class="post-it">
    <header>
      <div class="title">
        Day 28
      </div>
      <hr>
    </header>
  </div>
  <div class="post-it">
    <header>
      <div class="title">
        Day 29
      </div>
      <hr>
    </header>
  </div>
</div>

Answer №2

Give this a shot:

.sticky-note {
  display: inline-block;
}

Answer №3

The behavior you are experiencing is completely normal. Think of inline block like a line of text.

Note: pipes represent actual divs

What happens in the first row looks something like this (consider the following snippet as one line):

|****|***|
|

Now, when you add more text:

|****|***| <<< Oops, not enough space, go to next line
|

But the next line isn't A (because it is practically still the same line):

|****|***| 
| <<< A

It's a new empty line B:

|****|***| 
| <<< A
 <<< B

So what you need is floating, not inline blocks.

.post-it {
  background-color: #F00;
  height: 140px;
  padding: 1em;
  width: 150px;
  float:left;
  margin: 0 1.3em 1.5em 0;
  box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.50);
}

 .title {
   font-size: 2em;
   font-weight: bold;
   line-height: 1em;
   margin-bottom: .2em;
}

#today {
  height: 300px;
}
<div>
  <div class="post-it" id="today">
    <header>
      <div class="title">
        Day 25
      </div>
      <hr>
    </header>
  </div>
  <div class="post-it">
    <header>
      <div class="title">
        Day 26
      </div>
      <hr>
    </header>
  </div>
  <div class="post-it">
    <header>
      <div class="title">
        Day 27
      </div>
      <hr>
    </header>
  </div>
  <div class="post-it">
    <header>
      <div class="title">
        Day 28
      </div>
      <hr>
    </header>
  </div>
  <div class="post-it">
    <header>
      <div class="title">
        Day 29
      </div>
      <hr>
    </header>
  </div>
</div>

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

Images within the signature are not appearing as intended

Trying to find a way to display a company logo in an email signature without it being blocked by default on different email clients. Initially, I attempted uploading the image to the company website, but encountered the following error: So, I decided to t ...

Enhancing User Experience: Creating a Vue Button Component for Adding Items to Cart with the Power of Axios and Laravel Backend Integration

I have recently developed a Vue3 shopping cart with an "Add One" button feature. When the user clicks this button, it updates an input field of type "number" and sends a request to update the database using Axios along with Laravel's createOrUpdate me ...

AngularJS flip card animation

Exploring the new AngularJS method for animations during page transitions, I am keen on integrating a card flip effect (resembling http://jsfiddle.net/nicooprat/GDdtS/) body { background: #ccc; } .flip { -webkit-perspective: 800; width: 400px; height: ...

Tips for querying multiple elements that share a common ID and verifying if the input has been modified

I have a series of text inputs that share a common id prefix but differ slightly at the end. Whenever a user enters text in any of these input fields, I want to trigger a function. Currently, I have this functionality implemented with the following code: ...

Execute an UPDATE query in PostgreSQL for each item in the array

Imagine a scenario where a cart filled with various grocery items, each having a unique ID, is ready for purchase. When the "purchase" button is clicked, an array containing objects of each item in the cart is sent. The number of items in the cart can vary ...

Next.js - Anticipated that the server HTML would include a corresponding <div> within <div> tag

For a live demonstration, please click here In my current project, I am experimenting with creating a simple layout that adjusts based on the user's screen size. Specifically, on mobile devices, only the latest posts should be displayed. On desktops, ...

The node.js application was unable to locate the '../HMS/server/models/user' file

Hi there! I'm currently working on an application with a folder structure as shown below. I want to use the following line in my passport.js file: var User = require('../server/models/user'); However, I encountered the error below after tr ...

A guide on customizing bar colors in a jqPlot stacked bar graph

Is there a way to customize the colors for individual bars in a jqPlot stacked bar chart? I've searched through examples, but they all seem to use the default colors. How can I explicitly set different colors for each bar? Here is the current code sn ...

How can I navigate and click on a drop-down menu link in Python using Selenium and CSS selectors?

This is an example of the HTML code: <span class="MenuIcons searchButton"></span> ... (additional content) <a data-bind="" url="/ParagonLS/Search/Property.mvc/Index/1" tabdescription="RESIDENTIAL" subtabdescription="Criteria" subtab ...

JavaScript: Accessing the selectedIndex of a dropdown list in RadGrid

Currently facing an issue with utilizing the RadGrid control from Telerik. I am attempting to access and manipulate the value of a GridDropDowncolumn within RadGrid using JavaScript (while in edit mode). Does anyone have any suggestions for the correct Ja ...

Issue encountered: Unable to load resource - ajax file upload failed due to net::ERR_SSL_BAD_RECORD_MAC_ALERT error

I've implemented an AJAX form file upload using jQuery. After testing my code across multiple computers and browsers, I've encountered an issue on one Windows 8 machine running Chrome where the upload functionality fails with the following error ...

Display the accurate duration based on the dates selected in an HTML form automatically

If someone has office hours on Monday, Wednesday, and Friday from 7:00 am to 7:00 pm, and on Tuesday and Thursday from 10:00 am to 9:00 pm, the dropdown menu should display only the timings of 7:00 AM to 7:00 PM if the selected date is a Monday, Wednesda ...

Unable to showcase the compilation in PDF form

I have a link on my page that, when clicked by the user, retrieves a list from the database using an ajax call and displays it. Now, I'm looking to add another link that, when clicked, will fetch the list from the database via ajax and present it in ...

JavaScript client side event that references the sender object ID in an aspx file

Can someone provide assistance with an issue in the code block below? function(s, e) { form1.hfRaiseEvent.value = s.ID; } This particular function is triggered when the Client Side Click Event occurs. From my understanding, s refers to the Sender Obj ...

Is it possible to retrieve calculated data from a child component and pass it to the parent component?

Is there a way to transfer computed data from a child component to a parent component? Currently, I am passing data from the parent to the child first and then I would like to utilize the computed property (data) in the parent component. This is crucial as ...

Is it possible to disable the "super must be called before accessing this keyword" rule in babelify?

My current setup involves using babelify 7.2.0 with Gulp, but I've encountered an error when working with the following code snippet: class One {} class Two extends One { constructor() { this.name = 'John'; } } The issue at hand i ...

What is the best way to merge two ajax functions into a single function?

I am looking to streamline my ajax functionality by combining two separate functions. One function is used to post a name, while the other is used to upload an image. I would like to create a single function that can handle both tasks of posting a name and ...

JavaScript - issue with event relatedTarget not functioning properly when using onClick

I encountered an issue while using event.relatedTarget for onClick events, as it gives an error, but surprisingly works fine for onMouseout. Below is the code snippet causing the problem: <html> <head> <style type="text/css"> ...

Is there a way to manipulate text in JQuery without altering the inner element?

I am struggling with an issue in my HTML code. Currently, I have the following structure: <h3 id="price">0.00<sup id="category">N/A</sup></h3> My intention is to use AJAX to replace the content within the <h3 ...

What is the best way to extract fields from one object and merge them into another object using Javascript?

Here is the scenario: $scope.book1 = { a = 1, b = 2 } This is the information retrieved from the database: $scope.book2 = { title = 2, author = 'joe' } What steps should I take to merge the data in book2 into book1, ensuring that all ...