What is the best way to arrange two horizontal divs so that they are stacked on top of each other when viewed on mobile

I'm struggling with getting two divs on my page to stack on top of each other when viewed on mobile. I've tried using @media queries in my CSS, but it's not working as expected. Any assistance to solve this issue would be greatly appreciated. Thank you in advance!

Below is the HTML code for the divs:

 <div id="page3">
            <div id="left3">
              <img src="images/entertowin_03.png">
                <h4>•text<br>•text<br>•text<br></h4>
            </div>

            <div id="right3">
            <img src="images/winnermap_06.png">

            </div>



        </div>
       <div id="dog">
        <image src="images/barrybottom_04.jpg"></image>
           <h3><a href="#neheader" class="class1">Back to top</a></h3>
        </div>

The CSS styling for the divs is provided below:

#page3 {
       background-image: url("../images/page3back_01.jpg");
    background-size: cover;
    width: 100%;


    min-height: 600px;
    font-size: 16px;
    height: 2em;
    display: flex;
    overflow:hidden;


}


#left3 {
    width:100%;
    padding-top: 5%;
    margin-left: 10%;
    max-width: 440px;
    height: 330px;
    display: block;
    flex: 0 0 65%;



}



#right3 {
    width: 100%;
    padding-top: 5%;
    margin-left: 10%;
    max-width: 440px;
    height: 330px;
    display:block;
    flex: 1;
    padding-top: 7%;


}

Furthermore, here is the media query code I attempted to use:

/** Responsive **/


#left3 {
  background-color: gray;
  float:left; 
  margin-right:20px;
  width:140px;
  border-right:2px solid #000;
}
#right3 { 
  background-color: white;
  overflow:hidden;
  margin:10px;
  border:2px dashed #ccc;
  min-height:170px;
}

@media screen and (max-width: 400px) {
   #left { 
    float: none;
    margin-right:0;
    width:auto;
    border:0;
    border-bottom:2px solid #000;    
  }
}

Answer №1

For desktop view, float both divs to the left and clear the container. Set their widths to 50% each to make them equal 100%. Then, in the media query, keep them floated but adjust their widths to be 100%.

#desktop-page {
    width:100%;
    clear:both;
    /*Additional styling */
}
#left-div {
    float:left;
    width:50%;
    /* Other styles go here */
}
#right-div {
    float:left;
    width:50%;
    /* Other styles go here */
}
@media only screen and (max-width: 400px)   {
    #left-div, #right-div {
        width:100%;
    }
}

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

What is the best way to position an <svg> graphic alongside text within a website?

In my current project, I am attempting to enhance the usability of a simple webpage by incorporating Bootstrap icons alongside text to distinguish between different options/items. However, I have noticed that the <svg> elements are slightly misaligne ...

Other browsers, such as Chrome and Firefox, are visible, except for Safari

https://testing007.s3-api.us-geo.objectstorage.softlayer.net/1A23CDC6F75811E6BFD706E21CB7534C---prof__6.jpg This link displays correctly on browsers like Chrome and Firefox, but does not show up on Safari. ...

Height problem with the data-reactroot component

On one of my web pages, there is a data-reactroot element with a height of approximately 1906px. However, the surrounding divs and html tags have a height of only 915px. I am trying to figure out how to make all the enclosing elements match the same heigh ...

Using CSS selectors in Framework7 Vue allows for precise targeting and styling

I am currently working on developing a Cordova/Phonegap application using vue.js and the Framework7. I have been able to utilize functions like "onClick" by using the "v-on:click="OnClick" attribute within an HTML element. It's worth noting that Frame ...

What could be causing my select element to not display any options after being dynamically generated using JavaScript?

function createDropdown() { const selectElement = document.createElement('select'); selectElement.setAttribute('type', 'text') toolresult.appendChild(selectElement); const optionElement = document.createElement('o ...

Using jQuery to trigger a click event on an image and display a hidden div

Currently, I am working on creating an image slice show to showcase various product images. The idea is to have smaller thumbnails that when clicked, will display a larger image in a different section. The default view will be the big image of img1. In a ...

Troubleshooting Margins in Bootstrap Container

Can someone help me figure out how to set consistent margins on a container using Bootstrap spacing properties without messing up the alignment?https://i.sstatic.net/unp8d.jpg * { box-sizing: border-box; } .container { max-width: 960px; } <div ...

The disappearing act of the Bootstrap 4 hamburger icon, despite the navbar expanding afterwards

Currently in the process of building my initial website using bootstrap 4, and encountering difficulties with my collapsible navbar and the hamburger icon. My goal is to have the navbar expand on medium screens, but switch to a hamburger icon on smaller sc ...

The previous link is still present in the current URL

Having some trouble with my button code here. I'm new to HTML and I have a button that references another HTML file using a parameter. <a class="btn btn-primary" role="button" href="reto_resultado/{{ clave_primaria }}">Check</a> The issu ...

Upload information into database without the need to refresh the webpage

Which programming language or tool would you recommend for efficiently loading data from a webpage into a database without requiring a page refresh? ...

Tips for resizing a navbar to match the image within it as the window size decreases

I'm having an issue with my navbar that contains both an image and a menu. Everything looks good when the window is maximized, but as soon as I start to resize it, the image and menu shrink while the navbar stays the same height. I've tried usin ...

utilizing javascript once form elements are dynamically inserted

While dynamically constructing form elements, I encountered an issue with generating unique IDs when the form is submitted. Everything works fine except for the JavaScript function responsible for populating the year in a dropdown selection. The issue ari ...

Transmitting information from HTML to a server using node.js

Having trouble sending data to the server? When running server.js in Node, I find that req.body.username and req.body.password are always undefined after clicking the submit button. The HTML file opens in a browser, so it seems like that is causing the iss ...

Pressing JavaScript buttons to trigger another button

I am looking to develop a script that generates a button which then creates another button. The subsequent button will be assigned an id attribute by incrementing from 1 to infinity. This feature should apply to all buttons (original button and the newly ...

Effective method for creating a responsive navbar

On my webpage, I have a navigation bar with three buttons on the left side and a search bar on the right side. While I attempted to write code to make them responsive for smaller screens, it seems that my approach was incorrect as they are still not respon ...

Problem with centering the content both horizontally and vertically

I'm struggling to get my content centered both vertically and horizontally. Also, my container-fluid isn't covering the footer when I inspect it in developer tools. I've searched through various resources but still can't seem to solve i ...

Switch the CSS class when clicking on a responsive table within a table

I am looking to update the background color of a row within a table when a tr is clicked. Below is the code for the table: <div class="table-responsive"> <table class="table table-hover"> <thead> ...

Dealing with the Access-Control-Allow-Origin error: a beginner's guide to enabling CORS with a straightforward web stack and Guice integration

Am I facing issues due to the technologies involved or is it my lack of understanding about them? Currently, I have an HTML5 application built with JavaScript and HTML, hosted on an Apache 2.2 server. Additionally, there is a Java application developed w ...

AngularJS ui-router in HTML5 mode is a powerful combination that allows

Hey, I'm looking to implement HTML5 mode in my project. Here's how my file structure looks: mypage.de/mysub I can only make changes within the "mysub" directory. So far, I've added the following into my index.html: <base href="/mysub/ ...

The issue of overflowing content and scrolling causing sections of the webpage to be hidden

I've been diving into HTML, CSS, and jQuery to enhance my personal website. However, I've encountered an issue when trying to implement larger menus - they don't display properly when scrolling, and I can't seem to pinpoint the reason. ...