The CSS flex display is not evenly aligned on the second row

I recently started learning about display: flex, and I'm still trying to get the hang of it. As you can see in the screenshot below, even after removing some content, the last two items are not behaving like the first row. I've tried different things but haven't been able to figure out why.

.menu {
  text-align: center;
}
.mainmenu {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}

.foodmenu {
  width: 30%;
  margin-top: 40px;
  text-align: center;
}

.foodmenu img {
  height: 230px;
  width: 230px;
  border-radius: 50%;
  max-width: 120px;
  max-height: 120px;
  margin-right: 10px;
}

.menutex {
  display: flex;
  align-items: center;
  margin: 20px;
}

.menuh5 {
  font: 1.2rem bold;
  border-bottom: 1px dashed #222;
  width: 200px;
  text-align: left;
  padding-bottom: 8px;
}

.menuh5 span {
  color: orange;
  float: right;
}

.per {
  text-align: left;
  margin-top: 4px;
}
<div class="menu">
  <div class="mainmenu">
        <div class="foodmenu">
            <div class="menutex">
                <img src="https://d1ouk4tp1vcuss.cloudfront.net/s3.amazonaws.com/ODNUploads/645966bbdb7c8Meat_Kibbeh.jpg?mode=crop&v=1&width=250" />
            </div>
            <div>
              <h5 class="menuh5">MEAT KIBBEH <span><b>$18</b></span></h5>
              <div class="per">per dozen</div>
            </div>
        </div>

        <!-- repeat this block for additional menu items -->

  </div>

https://i.sstatic.net/yBKK9.pngThe last two items seem to be misaligned, and upon adding three more items, they fall into place.

Answer №1

Make sure to review your HTML code as David suggested in the comment below.

You forgot to close the first "mainmenu" div and there's also no closing tag for the "menu" div.

<div class="menu">
  <div class="mainmenu">
    <!-- food menu -->
  </div>
  <div class="mainmenu">
    <!-- food menu -->
  </div>
</div>

I have also provided a cleaned-up version of your code on Codepen. Your CSS is good, just make sure to fix your markup.

Check out the updated version on Codepen

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

Adjusting the width of the header in Wordpress themes like Genesis and Foodie Pro

Struggling with the header appearance on my website. I want the blue section to be full width while keeping the logo and navigation the same width as the content area (1040px). I'm new to Wordpress and unsure how to make this adjustment. Someone sugg ...

Disable the div by graying it out when the button is clicked

In my jsni form, I have implemented a click handler on the save button. When the save button is clicked, I would like the specific div to be greyed out to indicate that data is being saved. var x=$doc.createElement("div"); x.id="nn"; var lbl=$doc.createEl ...

What steps should I take to ensure my navigation bar spans across the entire page?

I'm new to this and looking for help. I want my navigation bar to span the entire width of the page without any white spaces on the sides or top. Below is my CSS: nav ul {list-style-type: none; margin: 0; padding: 0; overflow: hidden; backgr ...

Several levels piled one on top of the other

I'm in the process of designing a section for a webpage using Bootstrap 3.0, and I want to layer three divs or sections on top of each other. The stacking order should be as follows: background "squares," footer, and foreground "squares" with images. ...

Mobile devices cause CSS drop shadows to malfunction | Next.js

Update: After some testing, I discovered that this issue is specific to iPhones. When I tested it with an android device, everything worked perfectly fine. However, when I tried viewing the page on two different iPhones, it broke on both. This problem see ...

Press the vertical navigation bar

My website is currently undergoing a major overhaul. I am looking to enhance its functionality, but I may have taken on more than I can handle. You can find the link related to my query here: On my top menu, there is a button located on the left side. It ...

Guide to setting the first tab as the default tab using Thymeleaf, Css, and Bootstrap

I am currently working on a project where I need to dynamically create tabs based on a list retrieved from my Spring backend using Thymleaf and Bootstrap. While I have managed to successfully create the tabs and content, I am facing an issue where the fi ...

Is it possible to achieve 100% screen height by combining a fixed height div with a stretchy height div?

I have a design concept that I'm trying to bring to life. I'm struggling with figuring out how to add another "stretchy div" to the layout. I want this second div to expand to fill all remaining vertical space on the screen without causing it to ...

What could be causing the issue with the pseudo-class :first-of-type not functioning correctly?

How come this piece of code executes successfully, querySelector("p + p"); while the following code snippet results in null? querySelector("p ~ p:first-of-type"); ...

The orientation of the navbar is set to vertical rather than horizontal

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script> <div id="navigation"> ...

JavaScript or jQuery can be used to rearrange the position of child divs within parent divs with a single action

I am facing a dilemma with 5 identical divs, each containing text and an image. My goal is to rearrange the child divs so that the text comes after the image in each article. Put simply, I want the image to be displayed above the text in all instances. Al ...

Having trouble displaying background images on GitHub pages?

I have encountered an issue with images not displaying correctly on GitHub Pages, despite trying various solutions suggested in previous posts. Strangely, the page functions perfectly on my local machine and on Netlify, but on GitHub Pages all the images a ...

Integrating a fictitious style using jQuery

Having some trouble with this code snippet. The issue arises when trying to apply the following style using jQuery. CSS .arrow_box { position: absolute; width: 24px; border-radius: 30px 30px 3px 3px; height: 17px; float:left; } .arrow_box:after { bord ...

Can you explain how the CSS hack *+html works?

While working on a project, I have encountered multiple rules that look like this: * + html { /.../ } Although I understand the purpose of using * and +, I am unsure about the significance of this particular construction. Additionally, I came across ...

Hover Effects for CSS Info Boxes

I have a code snippet below for an info box I am working on. How can I adjust it so that when I hover over it, the green background fills the entire height instead of just 3/4 of the height? Any guidance on what may be causing this issue would be greatly ...

Top method for identifying "abandoned words" within text that has been wrapped

Our content and design teams have a specific request to prevent paragraphs from ending with an "orphan word" - a single word on the last line of text that has wrapped onto multiple lines. The designer's proposed solution is to adjust the margins sligh ...

Having issues with a Retina iPhone interacting with a website built using responsive Twitter Bootstrap

I'm currently utilizing Twitter Bootstrap alongside responsive CSS for a web page that is optimized to run in a UIWebView. My goal is to ensure the consistency of the page's appearance across all iPhones, with an exception for images. These imag ...

Ways to align text and horizontal rule perfectly within a div container?

I need to add some text to my <div> container and make sure it is centered. .hr { background: green; height: 50px; margin: 65px 0; width: 3000px; } <div class="hr"></div> This is an illustration of my project: https://i.sstatic.n ...

Shifting of SVG coordinates

My challenge involves fitting an svg into a div. The svg consists of a single path. Even though I have correctly set up the viewBox and preserveAspectRatio, part of the path is drawn outside the expected boundaries. You can find the fiddle here, and below ...

What are the advantages of importing CSS files from JS source code with webpack, rather than building CSS in isolation as traditionally done?

If you're looking for information on how to load CSS with webpack, check out the documentation here: https://webpack.js.org/guides/asset-management/#loading-css1 The webpack documentation suggests importing CSS files from JavaScript code and using ex ...