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:

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

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

Add Text to Bootstrap Modal Window

The bootstrap modal body is not containing all of my content and some of it is overflowing. <div class="modal fade" tabindex="-1" role="dialog" id= "blockModel"> <div class="modal-dialog"> <div class="modal-content"> < ...

Formatting Text in CSS and HTML

I need help aligning three images horizontally with text underneath, using CSS. Despite trying multiple methods, the images remain vertically aligned and the text does not align properly with the images. #img_cont { display: table; width: 90%; ...

How can I fetch data from a ManyToMany jointable using Typeorm?

Is there a way to retrieve the categories associated with posts when fetching user data? Data Models: @Entity() export class Category extends BaseEntity { @PrimaryGeneratedColumn() id: string; @Column() name: string; @Column() description: s ...

Trigger event once item is selected from the jQuery combobox dropdown

I have implemented a custom autocomplete combobox using the jQuery UI library to create text fields with dropdown functionality. This hybrid input allows users to either select an item from the dropdown or enter free text manually. However, I need to trigg ...

Cufon failing to load following an ajax call

At first, cufon is used to replace the text on the main page. However, when another page file is loaded, cufon does not apply its replacement to the newly loaded content. Why is that? I tried adding cufon.refresh(); as the last function in the chain. I c ...

Utilizing CSS float with dynamic height

Is there a way to achieve height:auto; for a parent element even when child elements are using float:left; or float:right? Solution for the Parent Element: #parent { width:100px; height:auto; padding-bottom:10px; background:#0F0; ...

Ways to deactivate the Bootstrap collapse feature

In my accordion FAQs, I am facing an issue where Question 1 is automatically opened when the page loads. Additionally, when I click on Question 2, it closes instead of staying open. I would like to address these problems and make sure that each question st ...

Hamburger Menu in Bootstrap not functioning as expected

Despite following each step meticulously for implementing the Hamburger menu in the navbar, I encountered an issue. The navbar collapses when resizing the window but fails to open upon clicking it. Below is a sample code snippet for reference. It utilizes ...

Utilize HighCharts to seamlessly implement multiple series with the help of AJAX requests

I am facing an issue with plotting the performance results on HighCharts using AJAX. The problem lies with the .addSeries API call not functioning correctly. I need assistance in determining if my approach is correct. $(function () { $('#chart3&a ...

Passing a reference to a react functional component (react.FC) results in a type error: The property ref is not recognized on the type 'IntrinsicAttributes & Props & { children: ReactNode}'

Currently, I am working on mastering the utilization of forward refs. In a functional component (FC), I am trying to initialize all my refs and then pass them down to its child components so that I can access the canvas instances of some chartjs charts. Ho ...

What is the best way to ensure bidirectional text appears correctly when two conflicting languages are combined, ensuring explicit directionality is set?

As I work on localization implementation, I encounter an issue with the directionality of mixed characters on the page. The text content is stored in a json file and inserted into the DOM using a Vue.js template. While individual characters display corre ...

What causes TypeScript to interpret an API call as a module and impact CSS? Encountering a Next.js compilation error

My website development process hit a roadblock when I tried integrating Material Tailwind into my project alongside Next.js, Typescript, and Tailwind CSS. The compilation error that popped up seemed unrelated to the changes, leaving me baffled as to what c ...

Adding text with jQuery

Currently, I am utilizing the Jquery text editor plugin known as JqueryTE. While adding some functions to it, I have encountered a roadblock. Specifically, I am attempting to insert additional text into the source of the textarea but have been unsuccessfu ...

Passing props to a wrapped component when utilizing a higher order component in React

While exploring the react documentation, I came across a section on Higher-Order Components that included an example of logging props for a specific component. function logProps(WrappedComponent) { return class extends React.Component { componentWillR ...

Upon installation of Next.js, an error in the globals.css file quickly emerged, yet remarkably, it did not disrupt the code in

Here is the link to the repository: here. Once I created the next.js environment using the command "npx create-next-app@latest ./" and ran "npm run dev", I encountered the following error message:- ../../../#React Projects/My projects/causs/styles/global. ...

Is it possible for two-way binding to function in index.html within Angular 4?

Does two-way binding function in index.html? I have some links and metadata in index.html. How can we define head parameters in a component? <head> <meta name="og:title" content={{titleValue}}> <meta name="og:url" content={{urlValue}}> & ...

Python code to locate images within HTML source code

Searching for images in an html source code can be tricky. I prefer using regex over the html.parser method, but I'm open to learning if you can explain it simply like you would to a child. I wish I could use beautifulsoup, but mastering the hard way ...

Unable to start store from localStorage during App initialization

Having trouble setting up my Vuex store with the logged-in user's account details from localStorage. I've looked at numerous Auth examples in Nuxt, but none explain how to retrieve an authToken from localStorage on the client side for subsequent ...

Troubleshooting data binding problems when using an Array of Objects in MatTableDataSource within Angular

I am encountering an issue when trying to bind an array of objects data to a MatTableDataSource; the table displays empty results. I suspect there is a minor problem with data binding in my code snippet below. endPointsDataSource; endPointsLength; endP ...

Creating a quiz with just one question in React: A step-by-step guide

How can I add the functionality to handle correct and incorrect answers? I've designed a single-question quiz with multiple options. The Quiz component has been created. See the code snippet below: Quiz Component export default function Quiz(props) { ...