Troubleshoot why content justification and item alignment are not functioning properly in a flexbox layout

I am struggling to format divs using flexbox. The justify-content and align-items properties do not seem to be working as expected in my code. I have two flex column divs, but applying these properties has no effect. Below is the code snippet that I am currently working with, using Tailwind CSS and React.

The HTML structure consists of a main div that spans the width of the screen. Inside this div, there are two child divs. The first one is positioned absolutely and serves as a background for the left half of the parent div. The second child div is placed in the foreground and contains text and image content with padding on the sides. My goal is to apply flex properties to these child divs.

{/* container */}
 <div className="w-screen relative mb-10">
        // Background shape div to give color background to the left half
        <div
          id="backgroundShape"
          className="w-1/2 bg-grey-400 absolute h-full -z-20"
        ></div>
        
        <div className="mx-auto container px-6 xl:px-28 flex py-10">
          // Left half of content
          <div className="w-1/2 flex-col justify-center pr-20 ">
            <div>
              Heading 1
            </div>
            <div className="text-4xl">
              Heading 2
            </div>
            <div className="grid grid-cols-2 grid-rows-2 gap-x-6  gap-y-3">
              <div>
                <FaScroll className="" />
                <h3 className="text-lg">
                  Subheader
                </h3>
                <p className="text-sm">
                  Description
                </p>
              </div>
            </div>
          </div>

          // Right half of content displaying two images
          <div className="w-1/2 flex-col pl-10 justify-center">
            <div>
              <img
                src="https://www.w3schools.com/images/w3schools_green.jpg"
                alt="image"
              />
            </div>
            <div>
              <img
                src="https://www.w3schools.com/images/w3schools_green.jpg"
                alt="image"
              />
            </div>
          </div>
        </div>
      </div>

The background div with id="backgroundShape" uses clip-path property to create a unique shape. Although I think this is not related to my current issue, I wanted to include the style information here for reference.

#backgroundShape {
  clip-path: polygon(95% 0, 100% 50%, 95% 100%, 0 100%, 0 0);
}

If any clarification is needed, feel free to leave a comment. Any assistance on this matter would be greatly appreciated. Thank you!

Answer №1

the items-center and justify-center classes were not added because the flex class was missing from the child divs. To correct this issue, simply make the following changes:

// div holding text and image content for foreground
        <div className="mx-auto container px-6 xl:px-28 flex py-10">
        // left half of content displayed over background div
          <div className="w-1/2 flex flex-col justify-center pr-20 ">
            <div>
              Heading 1
            </div>
            <div className="text-4xl">
              Heading 2
            </div>
            <div className="grid grid-cols-2 grid-rows-2 gap-x-6  gap-y-3">
              <div>
                <FaScroll className="" />
                <h3 className="text-lg">
                  Subheader
                </h3>
                <p className="text-sm">
                  Description
                </p>
              </div>
            </div>
          </div>

          // right half displaying two images in a column
          <div className="w-1/2 flex flex-col pl-10 justify-center">
            <div>
              <img
                src="https://www.w3schools.com/images/w3schools_green.jpg"
                alt="image"
              />
            </div>
            <div>
              <img
                src="https://www.w3schools.com/images/w3schools_green.jpg"
                alt="image"
              />
            </div>
          </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

I wonder why serialize() is not returning a response to me

As someone who is just starting to learn jQuery, I've been experimenting with the .serialize method in jQuery. Unfortunately, I haven't had much luck getting it to work properly. Despite connecting to the latest library (version 3.4.1) and checki ...

Utilizing Django to Retrieve HTML LIST Data Seamlessly Without Forms or Models

After creating an HTML page containing a series of list items, I wanted to implement a feature where clicking a button would read the data within the list and perform a transformation. I came across an example similar to this on Stack Overflow. However, t ...

Positioning additional elements underneath the two div elements that were previously aligned next to each other

Here is the code I attempted: #tools { float:left; } #sketch { border: 10px solid grey; float:left; width: 700px; height: 500px; position: relative; } This is the HTML code snippet: <div id="tools"> <p>These are ...

Styling Material UI components with CSS is a great way to

I'm facing difficulties while working with Material UI components. Currently, I have a Material UI table and I want to center-align the text within it. The standard CSS of Material UI contains an element named MuiTableCell-root-60 which has a text-a ...

Is there a notable distinction when utilizing http for referencing assets?

As I work on creating a new website, the question of displaying images has come up. I plan on using an img tag, but I'm unsure if it matters how I structure the source link: <img src="img/mypic.png"> or like this: <img src="http://www.mysi ...

Is there a way to automate testing for my web application bundled with webpack against FUOC?

After creating a React + Redux web app bundled with webpack, I encountered a bundling error that caused my website to display flash of unstyled content (FUOC) behavior. Certain components did not inject their CSS into the server response, resulting in pa ...

Structuring PHP, HTML, and jQuery files on a website

I'm a beginner in web development and currently working on a school project to create a basic educational video platform. My next task involves turning my site into a single page application, which I plan to accomplish with the help of jQuery and AJAX ...

The content spills over when applying the Bootstrap Grid system

I am working on creating a display heading that includes images on both the left and right sides of the heading. The layout looks great on larger displays, but as I shrink the display size, the text in the heading overflows the column on the right, causing ...

Tips for achieving a similar stroke and shadow effect using CSS

I'm struggling to achieve the desired effect with strokes, so I need some CSS advice. I also experimented with adding shadow to text: body { color: #000; -webkit-text-fill-color: #030303; -webkit-text-stroke-width: 0px; -webkit-text-stroke- ...

Utilizing R to Extract Data from HTML Webpages

I am currently extracting flight schedules from JFK's website. You can find the link to access the flight schedules right here; My initial approach involves inspecting a specific field of each flight and recording its xpath. The purpose is to first e ...

Positioning an individual element to the right side of the navigation bar in Bootstrap 5

I've been attempting to shift a single nav-item to the right side of the navbar, but I'm having trouble. My navbar is fairly basic, without a search tool or dropdown menu, as seen below: <nav class="navbar navbar-expand-lg bg-body-tertiar ...

Troubleshooting VueJS: Issues with V-for display behavior

Is there a way to use v-for to arrange table data in a format similar to the code below: <tr> <th scope="col">Name</th> <th scope="col">Price</th> <th scope="col">Product ID</th> <th></th& ...

Mastering the ngIf Directive in Angular: A Comprehensive Guide

Before you approve and publish, please take note: You are about to give your approval for the Industry Formile Deliverable. The content will be rendered when the specified condition is met. div class="form-group" ...

Add the information from the form to a JSON document

I am trying to add form data to a json file using the code below. However, I keep getting an error response whenever I submit the data via post. Can you help me identify where the issue lies? HTML <form class="ajax form-inline"> <div class="form ...

Conceal div2 upon clicking button1 and reveal div1 using Angular

When the "Edit" button is clicked, I want to display <div ng-if="hideShow">. Conversely, when the "Add" button is clicked, I want to hide <div ng-if="hideShow1"> and display another <div ng-if="hideShow1">. Currently, clicking on the "Ed ...

Calculating totals based on user input using an array as a variable in JavaScript

I am looking to store the total for a specific database object with the id of 3. There are various ids with different values, but in this instance, I am focusing on storing the value of 2. In addition to storing the value, I also want to be able to increm ...

What is the most effective way to determine the maximum length of data in each column within

Need help with setting the proper maxlength attribute for text fields in an HTML form based on maximum field length in MySQL database. Is there a way to query MySQL for this information? I currently use SHOW COLUMNS FROM {database name}, but it includes f ...

Refresh the browser to update the content of specific columns

$(".home").append($(".home .coco").sort(() => Math.random() - 0.5)); .row{margin-bottom: 30px;} <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" /> <script src="https://code.jquery.com/jquery-1.11.1. ...

The values of checkboxes are not stored as a comma-separated string

My current form setup resembles the following: <form action="MyForm.htm" method="GET"> <input type="checkbox" value="1" id="cb1" name="xxx"/> <input type="checkbox" value="2" id="cb2" name="xxx"/> <input type="checkbox" va ...

Determining the browser width's pixel value to enhance responsiveness in design

Lately, I've been delving into the world of responsive design and trying to grasp the most effective strategies. From what I've gathered, focusing on content-driven breakpoints rather than device-specific ones is key. One thing that would greatl ...