Guide on stacking two divs on each other in response to a decrease in screen width

In this particular section, there is a div labeled programDescriptionDiv. Inside programDescriptionDiv, there are two separate divs. Normally, these two divs each take up 50% of the screen width.

The goal is to have the second div stack below the first one when the screen size becomes too small to accommodate both on the same row. This should be achieved with the CSS property flex-wrap: wrap, but it seems to not be working as intended.

Currently, when the screen width decreases, the two divs just resize while still trying to fill 50% of the screen width each. The desired behavior is for the divs to stack vertically on top of each other instead. What could be causing this issue in the CSS?

Code Snippets:

<section class="programDescriptionSection">
  <div class="programDescriptionDiv">
    <div class="imageDiv">
      <img id="closingStemGapImage" src="../resources/closingStemGap.jpg" alt="">
    </div>
    <div class="paragraphDiv">
      <p class="homepageSectionParagraph">
        The Codigo Initiative aims to close the STEM opportunity divide in under-resourced Chicago-area school districts by connecting classroom
        teachers with tech-industry professionals. This pairing creates sustainable Computer Programming curriculums where volunteers support
        teachers as they learn the basics of Computer Programming.  Ultimately, the teachers will infuse their newly-found STEM skills into their
        existing classroom curriculums. The end-result is an enhanced classroom experience where teachers empower their students to compete in today's
        economy, and inspire them to create a better future for themselves and their communities.
      </p>
    </div>
  </div>
</section>
.programDescriptionSection {
  width: 100%;
  height: 30%;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  /* align-items: center; center all contents vertically */
  justify-content: center;
  /*center horizontally*/
}

.programDescriptionDiv {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  /*center all contents vertically*/
  justify-content: center;
  /*center horizontally*/
  width: 100%;
  /*make the section take up the whole width of the screen*/
  flex-direction: row;
}

.imageDiv {
  width: 50%;
  display: flex;
  align-items: center;
  /*center all contents vertically*/
  justify-content: center;
  /*center horizontally*/
  min-width: 50%;
}

#closingStemGapImage {
  /*Will fir the dimensions of the div dynamically.*/
  max-width: 100%;
  max-height: 100%;
}

.paragraphDiv {
  width: 50%;
  display: flex;
  align-items: center;
  /*center all contents vertically*/
  justify-content: center;
  /*center horizontally*/
}

.homepageSectionParagraph {
  font-size: 90%;
  width: 80%;
}

Answer №1

One reason for the issue could be the lack of setting a width constraint on your flex items. It is recommended to adjust the min-width property based on your breakpoint or utilize media queries for responsiveness.

.programDescriptionSection {
    width: 100%;
    height: 30%;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    /* align-items: center; center all contents vertically */
    justify-content: center; /*center horizontally*/
}

.programDescriptionDiv {
    display: flex;
    flex-wrap: wrap;
    align-items: center; /*center all contents vertically*/
    justify-content: center; /*center horizontally*/
    width: 100%; /*make the section take up the whole width of the screen*/
    flex-direction: row;
}

.imageDiv{
    width: 50%;
    display: flex;
    align-items: center; /*center all contents vertically*/
    justify-content: center; /*center horizontally*/
    min-width: 500px; /*set to your breakpoint*/
}

#closingStemGapImage{
    /*Will fir the dimensions of the div dynamically.*/
    max-width: 100%;
    max-height: 100%;
}

.paragraphDiv{
    width: 50%;
    display: flex;
    align-items: center; /*center all contents vertically*/
    justify-content: center; /*center horizontally*/
}

.homepageSectionParagraph{
    font-size: 90%;
    width: 80%;
}
<section class="programDescriptionSection">
            <div class="programDescriptionDiv">
                <div class="imageDiv">
                    <img id="closingStemGapImage" src="https://www.plextek.com/wp-content/uploads/default-placeholder-1024x1024-500x500-1.png" alt="">
                </div>
                <div class="paragraphDiv">
                    <p class="homepageSectionParagraph">
                        The Codigo Initiative aims to close the STEM opportunity divide in under-resourced Chicago-area school districts by connecting classroom
                        teachers with tech-industry professionals. This pairing creates sustainable Computer Programming curriculums where volunteers support
                        teachers as they learn the basics of Computer Programming.  Ultimately, the teachers will infuse their newly-found STEM skills into their
                        existing classroom curriculums. The end-result is an enhanced classroom experience where teachers empower their students to compete in today's
                        economy, and inspire them to create a better future for themselves and their communities.
                    </p>
                </div>   
            </div>
        </section>

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

Discover the identity of an element through the value of another element

Looking for a way to retrieve the id value based on the input value in this HTML code. For instance, I need to identify the id value associated with the input value of number2 - which is unknown2. How can this be achieved using jQuery? <th id="unknow ...

Jquery Fails to Execute When Clicking on Radio Button

Whenever a user selects a radio button, I want to display an alert box. I have already written the jQuery code to achieve this. Here is my implementation: <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></ ...

Tips for positioning an MUI element inside a container to extend to the edge of the browser window

Currently, I'm working on a project with a Material-UI (MUI) container that contains a Stack element. Within this Stack, there are two Box elements displayed in a row, each set to take up 50% of the width. In my design, I want the second box to break ...

Working with HTML5 Canvas to Clip Images

Is there a way to implement a tileset image in canvas like this one? I am trying to figure out how to make it so that clicking on the first tile returns 0, clicking on the tenth tile returns 9, and so on... Any suggestions on how to clip a tileset on an ...

What is the best way to make sure the embedded object fills the entire height of the container div?

I am currently using angular2/4 along with angular-material (https://material.angular.io/). My challenge lies in trying to embed a PDF within it. The issue I am facing is that the height of the PDF object seems to be small and doesn't fully occupy the ...

Customize bullet list icons to adjust in size based on content using css

In my CMS project, the CMS team has a special requirement regarding unordered and ordered lists. They want the size of the bullet list icon to adjust according to the text content within the list. The image below shows the default design of a list item: ...

Can you place 4 table cells in the first row and 3 table cells in the second row?

Exploring the world of HTML and CSS designs for the first time. Here's a code snippet I've been working on: <html> <body> <table width="100%"> <tr> <td width="25%">&#160;</td> ...

The replace() function is failing to replace the provided inputs

Supposedly, when a user types in certain profanity and submits it, the word is supposed to be replaced with a censored version. Unfortunately, this feature is not working as expected. The word appears uncensored. Do you think implementing if/else stateme ...

Concealing the TinyNav Drop-Down Menu

Currently, I am utilizing TinyNav on my website and it is working wonderfully. However, due to our extensive menu system, the tinynav dropdown appears quite large. I have been attempting to figure out a way to hide all sub-menus without success. I experim ...

Issues with HTML5 video playback have been reported in both Chrome and Firefox browsers

I'm having trouble getting the following HTML5 Video code to work. Can someone help me spot what I might be missing? <video width="267" poster="Poster.gif" height="209"> <source src="6Minutes_1.mp4" type="video/mp4"></source> <so ...

Disabling a jQuery function on an external page: Step-by-step guide

I have encountered a challenge while trying to load an anchor tag on an external page using a specific method: <a href="page.html#div> This method is meant to link me to another page's particular div. <div name="div"> stuff </> H ...

What are the steps to modify the text color in WKWebView?

I've customized my ViewController to include a WKWebView, where I load my content from both .html and .css files. The result resembles a controller for reading books within the Apple Books app. do { guard let filePath = Bundle.main.path(fo ...

Expand the image background to fit within a div container

Below is the code snippet I am working on: <div id="intro_section_upper" > <%= image_tag("video_background.jpg", :id=>"video_bg") %> <div id="video_table_main" > <table class=" ...

The CSS outline has a soft, rounded appearance rather than a sharp

https://i.sstatic.net/Mkb8Z.png Is there a way to prevent my outline from having rounded corners as it expands during the animation? Note: The issue seems to be present on Linux and MS Edge, but works fine on Mozilla Firefox. Any solutions for MS Edge us ...

Creating Immersive Web Pages

I am currently generating a large amount of data in HTML for periodic reporting purposes. The table consists of approximately 10,000 rows, totaling around 7MB in size. As a result, when users try to open it, the browser sometimes becomes unresponsive due t ...

Is it possible for a search box selection toggle to reveal a hidden information box underneath it containing all the compiled data?

Improve the user experience on my website by implementing a search feature for US states and Canadian territories. When visitors type in their selection, I want them to be able to click on an icon that will reveal relevant information about that choice. T ...

Issue with event.stopPropagation() in Angular 6 directive when using a template-driven form that already takes event.data

I am currently developing a citizenNumber component for use in forms. This component implements ControlValueAccessor to work with ngModel. export class CitizenNumberComponent implements ControlValueAccessor { private _value: string; @Input() place ...

I am trying to confirm in PHP whether any of the gender checkboxes have been selected. However, the code I have tried so far does not appear to be functioning as expected

Please refrain from suggesting the use of checked = "checked" in HTML, as the validation must be performed in PHP as per the requirements of my assignment. PHP Code: if (isset($_POST["gender"])) { $gender = $_POST["gender"]; if (($gender != "male") || ( ...

mobile screens causing bootstrap columns to overlap

The code I am working with is shown below: <div class="container"> <div class="col-md-3 calendar"> </div> <div class="col-md-9"> <button></button> (more buttons...) </div> < ...

Dynamic SVG positioning

Looking for a way to make this svg shape relative to its containing div? Fiddle: http://jsfiddle.net/8421w8hc/20/ <div> <svg viewBox="0 0 1000 2112" style="" xmlns="http://www.w3.org/2000/svg" version="1.1"> <path id="ma" st ...