Using HTML and CSS to create a flexbox layout with multiple rows

.ent__food__image {
  display: flex;
  justify-content: end;
}

.bev__food__image {
  display: flex;
  justify-content: end;
}

.kids__food__image {
  display: flex;
  justify-content: end;
}
<main class="flex-container">
  <!-- Entrees -->
  <div class="ent ent--container">
    <div class="ent__food__image">
      <img src="/food images/nutburger.jpeg" alt="nutburger" />
    </div>
    <h3>Entrees</h3>
    <div class="ent__item__1">
      <h4>Millet Burger</h4>
      <p>
        Millet patty served on whole wheat bun, with sauce, onions, pickles, tomatoes, romaine and sprouts. <span>7.59</span>
      </p>
    </div>
    <div class="ent__item__2">
      <h4>Nutburger</h4>
      <p>
        Nutmeat patty served on a whole wheat bun with sauce, onions, pickles, tomatoes, romaine, and sprouts.
        <span>7.59</span>
      </p>
    </div>
    <div class="ent__item__3">
      <h4>Vegan Burrito</h4>
      <p>
        Whole wheat tortilla with basmati rice, black or pinto beans, onions, tomatoes, hot sauce, sour cream, romaine and sprouts.
        <span>6.99</span>
      </p>
    </div>
  </div>

  <!-- Beverages -->
  <div class="bev bev--container">
    <div class="bev__food__image">
      <img src="/food images/strawberry-smoothie.jpg" alt="Strawberry Smoothie" />
    </div>
    <h3>Beverages</h3>
    <div class="bev__item__1">
      <h4>Lemonade</h4>
      <p>Small - 3.49 Large - 3.79</p>
    </div>
    <div class="bev__item__2">
      <h4>Pinapple</h4>
      <p>Small - 3.49 Large - 3.79</p>
    </div>
    <div class="bev__item__3">
      <h4>Strawberry Smoothie</h4>
      <p>Small - 4.89 Large - 6.99</p>
    </div>
    <div class="bev__item__4">
      <h4>Coffee</h4>
      <p>1.79</p>
    </div>
  </div>

  <!-- Kids Menu -->
  <div class="kids kids--container">
    <div class="kids__food__image">
      <img src="/food images/grilled-cheese.jpg" alt="Grilled Cheese" />
    </div>
    <h3>
      Kids Menu
      <span class="kids__description">Includes mini cookie and juice box</span
              >
            </h3>
            <div class="kids__item__1">
              <h4>Grilled Cheese</h4>
              <p>5.29</p>
            </div>
            <div class="kids__item__2">
              <h4>Quesadilla</h4>
              <p>5.29</p>
            </div>
            <div class="kids__item__3">
              <h4>PGJ</h4>
              <p>5.29</p>
            </div>
            <div class="kids__item__4">
              <h4>Shake (Choco, van, straw)</h4>
              <p>4.10</p>
            </div>
          </div>
        </main>

Hello, I am studying flexbox and feeling uncertain about how to implement it effectively. Is there a way to arrange the text and images in a side-by-side layout similar to the image below? Alternatively, should I explore using grid to address this issue? I'm also unsure if my current HTML structure supports achieving this desired layout.

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

Answer №1

Are you manually coding CSS? I must say, using Bootstrap 5 is a great decision as it fully supports flexbox. Check out this link

Here's how your HTML structure should look:

<main class="flex-container">
  <div class="container">
   <div class="row">
    <div class="col">
      Column
    </div>
    <div class="col">
      Column
    </div>
    <div class="col">
      Column
    </div>
   </div>
  </div>

This will greatly benefit you. Also, avoid using double dashes and underscores excessively, while they may work, it's not considered good practice.

Answer №2

While your question was quite broad, I hope this information provides some help to you.

.test_css {
    display: flex;
    flex direction: column; /*columns*/
    flex-wrap: wrap; /*if needed*/
    align-items: flex-end; /*puts the class at the bottom, add only if you want that space between the boxes 1 & 2 and the sketched ones below*/
}
or
.test_css2 {
display: grid;
justify-content: center; /*center*/
align-content: end; /*bottom, adds that gap between the two sets of boxes*/
grid-template-columns: 12px 12px 12px; /*how big & how many columns*/
grid-template-rows: 12px 12px 12px; /*how big & how many rows*/
}
It's hard to gauge their effectiveness without more specific details, but this should give you a starting point.

If you're still getting comfortable with flexbox, I suggest checking out to refresh your memory on commands and understand any differences you might be unsure about. Additionally, consider incorporating both grid and flexbox in your CSS rather than solely relying on flexbox. I personally use as a reference for grids. Best of luck with your project!

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

Using CSS units such as vw, vh, or percentage to specify height is not possible

In my Ionic app, I am adjusting the width and height of a div based on the viewport dimensions. This setup functions correctly on the browser and Android 4.4 devices. However, it does not work as expected on Android 4.2 (the height is constrained to the te ...

HTML5 Local Storage allows web developers to store data locally within

After saving a value in the local storage (HTML5) on page 1, I noticed that when I navigate to page 2, the values stored in the local storage disappear. Any insights or suggestions on what might be causing this issue? Upon reviewing my code, I am using th ...

Display the text area when the "Yes" radio button is clicked, while it remains hidden either by default or when the "No" radio button is selected

I am currently working on an html code and I am looking for a way to use java script in order to create a text area box only when the "Yes" radio button is selected. This text area should be hidden by default or when selecting "NO". <table class="tab ...

What methods can I use to make sure the right side of my React form is properly aligned for a polished appearance?

Trying to create a React component with multiple input field tables, the challenge is aligning the right side of the table correctly. The issue lies in inconsistent alignment of content within the cells leading to disruption in overall layout. Experimente ...

Refresh your webpage automatically without the need to manually refresh after clicking a button using AJAX in HTML and PHP!

One issue I'm facing is that the page doesn't auto-refresh, although it loads when I manually refresh it. Below you can find my HTML and AJAX code along with its database details. The Trigger Button <?php $data = mysqli_ ...

Tips for personalizing tooltips in Bootstrap 4

Currently, I am utilizing Bootstrap '4.0.0-alpha.6' and attempting to customize the tooltip styles. Despite adding a custom CSS class along with using Bootstrap 4, the tooltip is not responding correctly to my specified style when hovering over. ...

Inconsistency in field generation in WordPress Contact Form 7 causing issues

After utilizing the WordPress plugin Contact Form 7 to put together a straightforward questionnaire, I discovered that two fields, Your Birthday and Your Email, were mistakenly generated on top of one another in the final output. You can take a look at th ...

The e.currentTarget attribute in Material UI buttons is a key element that

I am facing an issue with implementing three tabs and buttons in my project. Each button should display a corresponding message when selected I have tried using e.currentTarget but no success so far. Can someone guide me on how to resolve this problem? You ...

Troubleshooting inactive CSS hover animation

Greetings! I'm facing an issue with a CSS hover animation. Here are two demos I've created: In the first DEMO, the animation works perfectly. However, in the second DEMO, it doesn't seem to be functioning. On the second demo, there are two ...

Ensuring various conditions with ngIf

I've created a toggle function that updates the text of a link, but I'm struggling to handle multiple conditions. For example, *ngIf="condition1 or condition2". Below is an excerpt from my code: <a routerLink="/ads" class="tip" (click)="togg ...

User interface for creating a platform resembling Product Hunt or Reddit

I am currently developing a web application similar to Product Hunt. The back-end API is up and running smoothly, and I have successfully implemented AngularJS for the front-end. However, I lack experience in designing the look and feel of the site. Shou ...

Material-UI React Native components: Injecting Styles without Props

import {createStyles, WithStyles} from "@material-ui/core"; const styles = (theme: Theme) => createStyles({ root: {} }); interface MyProps extends WithStyles<typeof styles> { } export class MyComponent extends Component<MyProps ...

Is there a way to adjust the transparency of the reflection while utilizing the -webkit-box-reflect property?

Exploring the capabilities of the -webkit-box-reflect property in Chrome has proven to be quite interesting. By utilizing the code snippet provided below (taken directly from the Webkit blog), I have been able to achieve a fading reflection effect: -webki ...

Styling the active selection in nav class with bold attribute in Bootstrap/AngularJs

How can I apply the bold attribute to the currently selected nav bar item? <ul class="nav"> <li role="presentation" ng-repeate="item in items" ng-class="{'active':navLink == item.header}"> </li> &l ...

Changing <br> to a newline ( ) using JSOUP

Is there a way to efficiently replace all occurrences of <br> with a new line character (\n) in HTML using Jsoup? I'm looking for a clean solution that will result in the Element#text() outputting plain text without any HTML, but with &bsol ...

The NextRouter failed to mount

Currently, I am in the process of incorporating a search functionality into my property rental application. I have successfully added the Nextjs Router to handle the routing. However, when attempting to access localhost:3000/search, an error is encountered ...

Arrange the table by adding and editing before and after appending

I have a table data that needs to be dynamically appended. But I want to allow users to add new data using text input and also edit the existing data before and after it's appended. The problem is that when I append new data, it overwrites the previo ...

What is the process of uploading a video and showcasing it on an HTML page?

I have successfully uploaded images and displayed them on an HTML page. Now, I am looking to do the same for videos. Here is my current code: $('#addPhotosBtn').click(function() { $(this).parents().find('#addPhotosInput').click(); }) ...

Using TypeScript and Angular to modify CSS properties

I'm trying to figure out how to change the z-index CSS attribute of the <footer> element when the <select> is open in TypeScript (Angular 10). The current z-index value for the footer is set to 9998;, but I want it to be 0;. This adjustmen ...

Use the double data type in MySQL to handle null values when blank form fields are submitted

Currently, I am facing an issue with a form that I have created to update a mysql database using PHP and HTML. In my MySQL database, I have set the data type as double (3,1). The problem arises when I submit data to the database and leave some form input f ...