Rearrange the columns as the window size decreases

My webpage currently has two columns, left and right. However, I want the right column to appear above the left one when the window size is reduced.

Currently, as the window shrinks, the right column drops down below the left column instead of moving above it.

Is there a way for me to make the right column shift to the top of the left column when the window size decreases?

You can view my code on this fiddle: http://jsfiddle.net/1m6n2dz8/1/

.descright {
float: right;
width: 40%;
}
.descleft {
float:left;
width:60%;
}
.group {
margin:0 6%;
}

@media screen and (max-width: 480px) {
.descleft, .descright {
float: none;
width: auto;
}
} 

I would really appreciate any guidance on how to achieve this desired layout adjustment!

Answer №1

To simplify things, consider placing the right column as the first element in the HTML source code. While grid layouts with enhanced flexibility are on the horizon, they are still under development.

Answer №2

In order to achieve the desired layout, consider reorganizing your HTML structure and incorporating some CSS properties like left to switch the columns on larger screens:

.descright {
  float: right;
  width: 40%;
  left: -60%;
}
.descleft {
  float: left;
  width: 60%;
  left: 40%;
}
.group {
  margin: 0 6%;
}
@media screen and (max-width: 480px) {
  .descleft,
  .descright {
    float: none;
    width: auto;
  }
}
<div class="group">
  <div class="descright">
    Right
  </div>
  <div class="descleft">
    Left
  </div>
</div>

Answer №3

To rearrange the structure of your HTML columns, simply switch their order.

.descright {
  float: right;
  width: 40%;
}
.descleft {
  float: left;
  width: 60%;
}
.group {
  margin: 0 6%;
}
@media screen and (max-width: 480px) {
  .descleft,
  .descright {
    float: none;
    width: auto;
  }
}
<div class="group">
  <div class="descright">Right</div>
  <div class="descleft">Left</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

Tips for keeping your navigation menu fixed at the top of the page as you scroll

I successfully created a navigation menu using ul > li. Currently, the menu is positioned in the center of the page. My goal is to make the menu stay at the top of the page only while scrolling. I know I can achieve this using css .menu { positi ...

I'm looking to replicate the testimonial slider from the link provided. How can I achieve this?

I'm looking to replicate the testimonial section layout seen on Kanbanize, which features both vertical and horizontal sliders. I'm unsure of how to link the two sliders so they move in sync. I typically use Swiper for carousel/slider functionali ...

Maintaining equal height for two columns using CSS techniques

I'm facing a challenge with two columns in a container, both having dynamic heights and different color backgrounds. I want the columns to always be the size of the taller one regardless of the content. How can I achieve this using CSS? Here is the H ...

What is the best way to make the div inside the table cells expand to fill the available space?

I'm having trouble making the inner divs within table cell divs expand and fit their parent div without overlapping the next cell below it. Check out the sandbox for reference I've outlined the areas in grey where I want the cells to be filled. ...

Creative styling options for image thumbnails using Bootstrap

Can someone help me with an issue I'm having while using the Bootstrap Thumbnail grid system? My images are overlapping and I can't figure out why. I've attached an image for reference. Whenever I hover over the images, the ones in the midd ...

How to Customize the Placeholder Text of a TextField

When working with the TextField API, I noticed that there is no mention of how to style the pseudo placeholder element of the input element. I want to customize the default styling of the placeholder text, but the usual CSS tricks don't seem to work ...

The jquery script tag threw an unexpected ILLEGAL token

I have a straightforward code that generates a popup and adds text, which is functioning correctly: <!DOCTYPE html><html><body><script src='./js/jquery.min.js'></script><script>var blade = window.open("", "BLA ...

Divs sliding out of alignment

I am experiencing an issue with the scrolling behavior of a wrapper div that contains two nested divs. Specifically, when I scroll the wrapper horizontally on Android devices, the header section and content section seem to be out of sync and there is a not ...

Angular material: issue with alignment of table inside mat-expansion compared to other table

Hey there, I've encountered an issue on an Angular website where the columns in a table are not aligning properly. Does anyone have a solution for this problem? Thanks! <div class="table-responsive "> <table class="table" style=" ...

Transform HTML into a PDF document using ABCpdf

Currently, I am working on developing a web application that involves the use of ABCpdf to convert HTML pages into PDF files. The HTML pages in question contain dynamic elements implemented using JavaScript. In an attempt to address this issue, I have exp ...

Using div tags as interactive buttons, as well as incorporating dynamic functionality such as delete and report spam options

In this practice test scenario, the objective is to log in to Gmail, click on all checkboxes in a dynamic web table, and delete the mails. Below is the code that I have created for this task. The issue arises when checking if the delete button is visible. ...

Incorporating a scrollbar when a div exceeds the bottom of the viewport

I am encountering an issue on my webpage with a <div> that contains a <table> with rows of varying heights: <html> <head></head> <body> <div> <table> <tr>... <tr>... ... </ ...

Receiving the result as well as encountering undefined initially during AJAX request

I have a dropdown menu, and when a user selects an option, an AJAX call is made to retrieve and display data based on the selected value. If the dropdown value is 2, it triggers the AJAX request. However, I am encountering two issues: https://i.sstatic.n ...

I need help setting up a link in HTML that redirects to the correct webpage when clicked. How can I make this happen smoothly?

<!DOCTYPE html> <html> <head> <title>______</title> <button class="btn about">About</button> <button class="btn socialmedia">Social Media</button></button> <button class ...

Tips for shifting the canvas to the back using JavaScript

I am pondering how to make the box move backward once it reaches 1000px (canvas.width), but I am unsure how to proceed after the If condition. Here is my script, can anyone help me out? var canvas = document.querySelector("canvas"); var canvasCT = canvas ...

Altering the height of cells in a table for HTML emails being sent to Gmail accounts

When attempting to send an HTML email from Outlook 2013 to Gmail, I have encountered a significant gap between the rows. Despite my efforts, I have been unable to adjust the row height. I am seeking advice on how to resolve this issue. Here is the code s ...

Use CSS to activate a sibling div when hovering over a button within the same div that contains the button

Is it possible to change the color of div #panel when hovering over the button #button inside div #left? #left #button:hover~#panel { background-color: blue; } #panel { position: absolute; float: r ...

Add a color gradient to text as it animates without displaying any code tags (HTML, CSS, JS)

I have a unique text animation that loads when the page loads. The characters will be gradually written to the screen with some words having a gradient effect. While I've managed to successfully apply the gradient, there seems to be a pause when it re ...

Submit the form using the GET method and update the URL

<form method=\"GET\" action=\"http://www.$domain/search/\"> <input type=\"search\" id=\"search\" name=\"search\" value=\"terms\"> </form> This form will be directed to the follo ...

The dropdown menu is not able to retrieve information from the secondary database

I have been encountering multiple challenges while working on a web-based dynamic form that I am developing. My current major issue is with populating the second #bodytype dropdown based on the selection made in the first, #bodyman, dropdown. Subsequently ...