Adaptive Layout: rearranging the sequence of Div elements

I am having a simple webpage and I want to change the layout so that when the width is decreased, the "middle" div goes on top of the "left" div. Currently, the middle div is positioned below the left div, but I would like to make it overlap the left div.

Check out this link for reference.

This code snippet controls the layout:

div{
font-family:"Palatino Linotype", "Book Antiqua", Palatino, serif;
font-size:60px;
}

body{
margin:0;padding:0;
}

#header{
height:100px;
width:100%;
background:purple;
text-align:center;
position:relative;
}

.wrap{
width:100%;
text-align:center;
background:blue;
   overflow:hidden;
   white-space:nowrap;
}


#left{
display: inline-block;
   margin-top:10px;
   height:500px;
   width:300px;
   background:red;
}

#middle{
display: inline-block;
margin-top:10px;  
margin-left:10px;
height:500px;
width:1570px;
background:gray;
}


@media (max-width:1320px){
#left{
width:800px;
height:200px;
margin:20px auto;display:block;
}
#middle{
width:800px;
}
#bottom{
margin-top:100px;
}
}

@media (max-width:1625px){
    #right{
  width:100%;
  height:300px;
    }

}


/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=For Footer */
* {
padding: 0;
}
html, body {
height: 100%;
padding:0;
}

.forfooter{
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto;
}

#bottom{
/*position:absolute;
bottom:0;
width:100%;*/
height:100px;
background:orange;
}

.push{
height:0px;
margin-top:-100px;
}

To implement this layout in your HTML file, add the following elements:

<title>First Responsiveness</title>
</head>
<body>

<div class="forfooter">
<div id="header">Header</div>

        <div class="wrap">
<div id="left">left</div>
<div id="middle">Middle</div>
        </div>
        
<div class="push"></div>
    </div>

<div class="push"></div>
<div id="bottom">Bottom</div>

Answer №1

To determine which browser support is needed,

flexbox is a great tool for this task.

.container {
  width: 80%;
  margin: 10px auto;
  border: 1px solid grey;
  display: flex;
  flex-direction: column;
  padding: 25px;
}
#top,
#bottom {
  height: 50px;
  line-height: 50px;
  text-align: center;
  order: 1;
}
#top {
  background: #bada55;
}
#bottom {
  background: #663399;
  color: white;
}
@media screen and (max-width: 760px) {
  #bottom {
    order: 0;
  }
}
<div class="container">

  <div id="top">top</div>

  <div id="bottom">Bottom</div>
  
</div>

View Codepen Demo

Answer №2

Take a look at this interesting technique: http://jsfiddle.net/e42q63w5/1/ The key is to ensure that div#middle appears before div#left in your HTML structure and control their positioning using float: left | right

div{
font-family:"Palatino Linotype", "Book Antiqua", Palatino, serif;
font-size:60px;
}

body{
margin:0;padding:0;
}
#header{
height:100px;
width:100%;
background:purple;
text-align:center;
position:relative;
}

.wrap{

width:100%;
text-align:center;
background:blue;
    overflow:hidden;
    white-space:nowrap;

}


#left{
float: left
display: inline-block;
    margin-top:10px;  
height:500px;
width:20%;
background:red;
}

#middle{
float: right;
display: inline-block;
margin-top:10px;   
margin-left:10px;

height:500px;
width:75%;
background:gray;
}

@media (max-width:1320px){
#left{
    float: none;
width:800px;
height:200px;
margin:20px auto;
        display:block;
}
 #middle{
    float: none;     
width:800px;
}
#bottom{
margin-top:100px;
}
}
@media (max-width:1625px){
#right{
width:100%;
height:300px;
}

}


/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=For Footer */
* {
padding: 0;
}
html, body {
height: 100%;
padding:0;
}

.forfooter{
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto;

}

#bottom{
/*position:absolute;
bottom:0;
width:100%;*/
height:100px;
background:orange;
}


.push{
height:0px;
margin-top:-100px;
}
<div class="forfooter">
        <div id="header">Header</div>

        <div class="wrap">
            <div id="middle">Middle</div>
            
            <div id="left">left</div>
        </div>
        <div class="push"></div>

    </div>
<div class="push"></div>
        <div id="bottom">Bottom</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

Implementing a spread operator in React.js with TypeScript to add the final element only

I'm currently facing an issue with adding an element to an array in react.js this.state.chat_list.map(elem => { if ( elem.name .toLowerCase() .indexOf(this.props.searching_username.toLowerCase()) !== -1 ) { this.setState( ...

Is it possible to retrieve the value of a particular field from a table?

My goal is to create a table that displays data about various users awaiting admin approval. Each row represents a specific user, and when the approve button on a particular row is clicked, I want to open a new window displaying detailed user information f ...

Substitute the gaps except for those within parentheses

I am exploring the idea of using multiple regex patterns to achieve my goal easily. Essentially, I am looking to replace all spaces in a string except for the ones that are enclosed within parentheses. Let's consider an example: Here is a string (th ...

How to retrieve the specific hidden input value in Vue.js that is stored within a div element

Hey there, I'm looking to store individual values of hidden inputs in my "card" divs. I've set up an onclick event that triggers the sendData() method, but it always returns the value "1". It seems like Vue is having trouble distinguishing betwe ...

Bootstrap 4's hamburger icon in the navbar toggler displaying only two lines, rather than three

I have created a navbar using Bootstrap 4. Although the navbar is functional, I am facing an issue that I have not been able to resolve on my own. When collapsed, the hamburger icon only displays two lines instead of three. I suspect that the problem lie ...

Repetitive Anchor IDs and Web Standards Compliance

Today, I encountered the task of converting outdated attributes on a page to make it more XHTML friendly. This led me to consider the anchor tag and its usage: Initially, I had anchor tags in the form of <a name="someName"></a>. However, upon ...

"Attempting to send JSON data via JsonResult is unsuccessful when trying to send a JSON object directly or using JSON

In my project, I have a class that looks like this: I've created a JsonResult method in the controller which takes an object of this class as a parameter: [HttpPost] public JsonResult NewAreaCode(AreaCode model) { return Json ...

Out of nowhere, an error emerged stating, "I am unable to access the 'name' property of undefined."

I am currently working on coding a Discord bot in JavaScript for a school project. However, I encountered an error while running my code that I can't seem to understand. This error never occurred before, and I suspect it might be due to a recent chang ...

Issues with Bootstrap-slider.js functionality

I'm having trouble getting the bootstrap-slider.js library from to function correctly. All I see are textboxes instead of the slider components. You can view an example at I have verified that the CSS and JS files are pointing to the correct direc ...

Creating a Method-Style Getter in Vuex

I'm currently diving into the realm of Vuex Method-Style getters and seeking clarity on how to properly implement them. Here's a reference Fiddle along with the code snippet: interface IData { name: string; } type IGetters = { data(gette ...

Instructions for adding and removing a class when a Bootstrap modal is scrolled past 300 pixels

Having trouble getting the scroll to top function to work on a specific div. I'm using window.scroll function but it's not functioning correctly. Can someone please assist? $(window).scroll(function() { var scroll = $(window).scrollTop ...

What is the process for connecting an Angular .ts file with an existing HTML page?

As I finish up the html pages for my website, I find myself in need of integrating Angular to complete the project. My experience with Angular so far has been with ionic apps, where the CLI generates the html, ts, and css pages. However, I am curious if ...

Error: The data from the intermediate value cannot be parsed using the parseFromString() method and replaced with another value,

I'm working on a project where I need to display parsed HTML content within an element. However, before displaying it, I need to make some changes to the HTML using the `replace` method. But unfortunately, I encountered a TypeError: (intermediate valu ...

Retrieve the JSON array value from the observable and pass the information to the frontend

Attempting to retrieve a JSON array from a json-server using observables, then passing the value to the frontend for search functionality on the received JSON array. Created a service and utilized HTTP get method to establish a connection with the server ...

Hidden button trigger is malfunctioning

I am attempting to activate a hidden button, but the event does not seem to be triggering. Here is the code snippet: <div class="dyn-inp-group"> <div class="dyn-inps"> <div class="form-group form-group-options col-xs-12 dyn-inp" ...

Encountering the issue of "Cannot read properties of undefined" while attempting to pass data to a prop

Currently, I am developing a Vue application that heavily relies on charts. The issue lies in the fact that I am fetching data from the database individually for each chart component, resulting in multiple calls and a slower page load time. I am looking to ...

Modify the output string using the `ol.control.MouseControl` function

I need to modify the output text within the target attribute of ol.control.MouseControl (version 3.15.1 of openlayers). Currently, the code only displays longitude and latitude values, but I want to include the strings "long" and "lat" before each value. ...

Can the orientation of a camera be altered using javascript and html?

I'm working on developing an HTML/Javascript camera application that utilizes live video feed. The device it's intended for has a tall screen resolution of 1080x1920. Unfortunately, I've encountered an issue where the camera feed doesn' ...

Using a jQuery if statement to target a particular div and apply custom CSS styling

I have encountered a unique challenge that I am struggling to solve. Imagine I have a 3x3 table created using div elements, and one of the cells has a background color of #999. My goal is to use jQuery to check if a specific cell has this background color, ...

Speedily deliver a message to the designated destination

I have a specific route set up at /test: app.route('/test', (req,res)=>{ res.sendFile(__dirname + "\\myhtml.html") }) Now, I want to trigger an event in Node.js on the /test route, and have myhtml.html file listen for ...