Is there a way to reposition a flexboxed sidemenu from the bottom of the screen to the top for mobile devices?

I'm having trouble rearranging the layout of my webpage. Currently, my sidebar element appears below the main content on mobile devices, but I would like it to show above the main content instead. I have utilized flexbox for most of my design, separating the main content into one box and the sidebar into another. On large screens, the sidebar correctly sits on the right side. Is there a way to achieve the desired layout change on mobile devices while keeping the desktop version intact? Any assistance in resolving this issue would be greatly appreciated.

To provide a better understanding of the situation, I have uploaded the code for the wrapper, main content, and sidebar on CodePen: https://codepen.io/Pinchofginger/pen/WddJQW?editors=1100

For reference, you can also view an image of the current layout here: https://i.sstatic.net/RUvtQ.jpg

Below is a snippet of my HTML and CSS code:

HTML


Insert your HTML code here.

CSS


Insert your CSS code here.

Answer №1

To achieve the desired layout, utilizing flex order and media queries is the way to go. You can view the implementation on CodePen.

Here's the HTML structure:

<body>
  <main></main>
  <aside></aside>
</body>

And here are the corresponding CSS styles:

body {
  display: flex;
  height: 100vh;
}

main {
  background: red;
  width: 90%;
}

aside {
  background: blue;
  width: 10%;
}

@media all and (max-width: 760px) {

  body {
    flex-wrap: wrap;
  }

  aside, main {
    width: 100%;
  }

  aside {
    order: -1;
  }
}

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

How to assign multiple selection values in Bootstrap's select picker

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.7.5/css/bootstrap-select ...

CSS - With the abundance of positioning methods available, determining the right approach can be quite a puzzle

As I delved into web development, my fascination with positioning grew. In the beginning, my novice websites were structured like this: <body> <h1> Welcome to my website. </h1> <br> <br> <br> <br> <br> ...

Deactivate rounding numbers in jQuery AJAX

When using jQuery to send numbers, I noticed that the decimals are not saved correctly. For example, 2.5 is saved as 3 and 17.5 is saved as 18. $("#sendnomreform").on('submit',(function(e) { e.preventDefault(); $('#loading').s ...

Assigning the href attribute dynamically

How can you dynamically set the href attribute of the <a> tag using jQuery? In addition, what is the method for retrieving the value of the href attribute from the <a> tag with jQuery? ...

What is the best way to send a string literal as a parameter to a method triggered by a click event

I'm trying to pass a string literal to a method as a click handler. <button (click)="changeLanguage('en')">EN</button> The above code is not working. Any suggestions on how to achieve this? ...

Tips on positioning flex items to create a visually appealing bar chart design

I've been working on customizing the appearance of a React component to resemble a horizontal bar chart. However, I'm facing difficulties aligning the center div to the left as intended. Below is the code for my React component for each row: imp ...

The Textfield component in Material UI now automatically sets the default date to the current date when using the "date" type

I am using Material UI's textfield with the type set to "date" and I'm experiencing an issue where the date defaults to the current date instead of mm/dd/yyyy. Is there a way to prevent this behavior and display mm/dd/yyyy when the user loads the ...

Personalize your Slick.js

I want to customize the navigation buttons for my Slick.js jQuery slider by replacing the default dots. Since I'm not very experienced with jQuery, I need help writing code that will sync the slider with my custom buttons. ...

How to Extract Information from a Table Enclosed in a Div Using HTML Parsing?

I'm new to HTML parsing and scraping, looking for some guidance. I want to specify the URL of a page (http://www.epgpweb.com/guild/us/Caelestrasz/Crimson/) to grab data from. Specifically, I'm interested in extracting the table with class=listing ...

Entire body encompassing table

I am trying to create an HTML page with a table that spans the entire body and displays scrollbars when needed for both horizontal and vertical scrolling. Here is my current styling for the table: table { box-shadow: inset 0 0 10px #000; position: ...

Invoke a function in Angular when the value of a textarea is altered using JavaScript

Currently, I am working with angular and need to trigger my function codeInputChanged() each time the content of a textarea is modified either manually or programmatically using JavaScript. This is how my HTML for the textarea appears: <textarea class ...

An issue has been encountered within the node modules directory at the path node_modules/@angular/flex-layout/extended/typings

I encountered an error in my Angular 6.0.8 application while using Angular CLI and running from VSCode. ERROR in node_modules/@angular/flex-layout/extended/typings/style/style.d.ts(72,67): error TS1144: '{' or '; ' expected. no ...

Trouble aligning CSS UL/LI menu in the center

Could someone help me with centering my CSS UL menu? I've posted the code below, as I'm still learning CSS and would appreciate any guidance. I've only been able to center it by setting a fixed width and using HTML center tags, but I need t ...

Issue with scrolling feature in div

I am currently facing an issue with scrolling on my website. Visit this site to see the problem. When scrolling down, it causes the "hidden" part of the site to slide up. I want to achieve a similar sliding effect, but it needs to be smooth. I have attempt ...

What's the best way to prevent extra spacing when typing in a materialUI TextField?

Instructions for the user: Please input your first name without any spaces between characters. I attempted to implement the following code, however, it did not achieve the desired outcome. <TextField required id="name" label="First Name" ...

Error - IO Is Not Defined in Socket.io

Currently, I am developing a real-time chat web page. Initially, I was considering using PHP, but I am experimenting with socket.io for the backend. However, I have encountered an issue where the browser console displays Uncaught ReferenceError: io is not ...

Showing headings in the table vertically

I have a header1 and header2 with corresponding data1 and data2 that I want to display differently. h h e e a a d d e e r r 1 2 data1 data2 To enhance the presentation, I wish to add borders around the head ...

Angular Collapsible Panel showcasing brief summary

I am struggling to implement an accordion feature in Angular that displays a brief description of the content initially, and when clicked on, reveals the full description. I need to truncate the content and display it in the header. Despite my attempts, I ...

Ways to toggle the visibility of an image using jQuery Mobile

I am working on developing an Android app using phonegap and I need assistance with toggling the visibility of an image based on a switch. When the toggleswitch is turned off, the image on the third page should be hidden. If the toggleswitch is turned on, ...

Is it not possible to change node labels in D3.js after clicking on a node?

After being inspired by this link, I successfully created a basic network visualization app using D3.js. The app reads node names from a textarea on an HTML page and then constructs a network where all nodes are interconnected. All the relevant code can ...