What are the steps to change the rendering order of Vue components in mobile view?

I have implemented 2 Vue components that split the page into two sections: left side and right side. These components are utilized on every page with the following structure:

<template>
  <div class="page-body">
    <left-side>
      <p class="text" >{{ $t('about') }}</p>
    </left-side>
    <right-side>
      <p class="slogen bottom">{{ $t('slogen') }}</p>
    </right-side>
  </div>
</template>

However, there is a scenario where these two components need to switch places in order to display the right-side component before the left-side component when using responsive mobile design. What would be the best approach to achieve this functionality? My Vue version is 2.3.3.

Answer №1

Here's a CSS query that uses flexbox and the order property to change the layout based on screen width.

In this example, the two colored areas swap positions when the display width is between 300 and 600 pixels.

.page-body {
  display: flex;
}

left-side,
right-side {
  background-color: #fdc;
  display: block;
  flex-basis: 50%;
}

right-side {
  background-color: #cdf;
  text-align: right;
}

@media (min-width: 300px) and (max-width: 500px) {
  left-side {
    order: 2;
  }
}
<div class="page-body">
  <left-side>
    <p class="text">{{ $t('about') }}</p>
  </left-side>
  <right-side>
    <p class="slogen bottom">{{ $t('slogen') }}</p>
  </right-side>
</div>

Answer №2

To easily achieve this layout using Vuetify, you can utilize the order property as shown below:

<v-row>
    <v-col class="col-11 col-md-6" order-md="2">
        <p>On mobile: content on the left; otherwise on the right</p>
    </v-col>
    <v-col class="col-11 col-md-6" order-md="1">
        <p>On mobile: content on the right; on tablet/desktop(-> md) on the left</p>
    </v-col>
</v-row>

Answer №3

To achieve this layout without using flexbox, you can utilize floats. Here's a brief example:

.right, .left {
  box-sizing: border-box;
  border: black 1px solid;
  width: 50%;
  height: 130px;
}

.left {
  float: left;
}
.right {
  float: right;
}

@media (max-width: 768px) {
  .left, .right {
    float: none;
    width: 100%;
  }
}
<div class="right">
  second
</div>

<div class="left">
  first
</div>

Answer №4

If you're using the vuetify framework and want to adjust the order of v-flex elements


For Larger Displays, such as Tablets and Laptops:

To reverse the row-wise order from |A|B| to |B|A|, use a scoped css similar to the following:

.layout.row.wrap {
        flex-direction: row-reverse;
      }

For Mobile View, changing the column order:

To reverse the order when displayed on mobile devices, utilize a scoped css like this:

@media (max-width: 425px) {
  .layout.row.wrap {
    flex-direction: column-reverse;
  }
}

You can set the max-width value as needed. If the reverse ordering is only required for one layout but not others, consider separating that specific layout into its own component where custom styling can be applied.

Learn more about Ordering Flex Items here

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

Duplicate multiple "li" elements using jQuery and place them in a designated position within the ul element, rather than at the end

I am currently working on developing a dynamic pagination bar. This pagination bar will dynamically clone the "li" elements based on a number received from an external webservice. Here is the structure of my pagination element: <ul class="pagination"& ...

Determine if a div contains an svg element with JavaScript

My question involves a div containing a question mark and some SVG elements. Here is the initial setup: <div id="mydiv">?</div> When validating a form submission in my code, I check if the div text contains a question mark like this: const f ...

Passing data between Vue.js components effortlessly without relying on events

At the moment, I am utilizing Laravel Nova. It's worth noting that it operates using vue.js. I've created a personalized vue component which requires the ability to modify data inside another component. This specific component is located in the ...

I am seeking assistance to utilize Flexbox to completely fill the height of my computer screen

Seeking assistance in utilizing Flexbox to occupy 100% of my computer screen's height, all while ensuring responsiveness: View of my current sign-in page on Chrome (Note the whitespace): https://i.sstatic.net/pJFOi.png Examining my existing fronten ...

The ReactBootstrap flexbox feature does not automatically adjust its height to match the content within

My struggle is with getting the height of this flexbox column to match that of its content. When the window width is less than 576 pixels, only one column is displayed per row. However, in this scenario, one of the columns (the teal one) ends up being too ...

Having trouble with aligning the Bootstrap grid in the center? Something seems to be off

I'm currently working on a project for Free Code Camp, but have encountered an issue. I am struggling to center the paragraph text below the image properly. The grid is set to 4 in this case. <div class="container"> <div class="row"> ...

Using CSS to repeat a background image horizontally starting from a specified position

I am currently working on styling an h2 element with a 2px background image. My goal is to have the image start right after the text in the h2 and repeat horizontally for the rest of the space within the h2. However, due to varying word lengths, I cannot s ...

What is the best way to make my navbar adjust seamlessly to accommodate the largest element?

Currently, I'm facing an issue where my logo is not fitting properly inside my navbar and it's "falling out." You can see the problem here: https://i.sstatic.net/l4T1B.png Here is the relevant code: HTML: <nav class="container-fluid navbar ...

Tips for rendering objects in webgl without blending when transparency is enabled

My goal is to display two objects using two separate gl.drawArrays calls. I want any transparent parts of the objects to not be visible. Additionally, I want one object to appear on top of the other so that the first drawn object is hidden where it overlap ...

Design a dynamic rectangular division using CSS and Bootstrap 4 that adapts to different screen sizes

I am encountering difficulties attempting to replicate a full-width rectangle div on a website, particularly with issues related to responsiveness and mobility. Here is an example of the design I am trying to recreate. And here's what I've acco ...

What could be causing the Grid Child, which has a fixed width and a max-width of 90%, to overflow the

Question: Could you please explain why the .header element overflows its grid track when the viewport width reaches 1500px? Code:: * { box-sizing: border-box; padding: 0; margin: 0; } body { background: #6e28d9; color: white; } .container { ...

Boundary around an object within a unified picture

I'm facing a bit of difficulty with a task. I need to add a border around an element within an image (I can't insert an image due to low reputation), and this border should match the width and height of the element exactly. It also needs to be re ...

Tips for managing error messages within inline input fields in Bootstrap 4 and CSS3

I currently have 2 input fields side by side that need to be validated using vee-validate in my Vue.js application. https://i.sstatic.net/xOZT2.png The validation error message is appearing at the end of the input-group instead of within it. https://i.s ...

Guide to creating a parallax scrolling effect with a background image

My frustration levels have hit an all-time high after spending days attempting to troubleshoot why parallax scrolling isn't functioning for a single image on a website I'm developing. To give you some context, here's the code I've been ...

What is the correct way to utilize HTML5 and jQuery to dynamically switch style sheets using the onclick SwapStyleSheet function, but this time locating the CSS files in a separate "css" folder instead of combining them all in

Here is a link to a Stack Overflow answer that explains how to change a stylesheet using a dropdown box: How do I change stylesheet using a dropdown box? I successfully implemented a jQuery onclick SwapStyleSheet function that works perfectly. However, I ...

Creating intentional blank space before the <Span> element using CSS in HTML

Currently working on a table with some spanned elements for customization. One issue I am facing is the persistent blank space above the blue spanned element in grid 6. Even when adding more spans to grid 6, they just jump below the blue one. How can I mak ...

The initial toggle switch is not visible

https://i.sstatic.net/6BMaY.png After running this code, I'm facing an issue where the first toggle switch is not visible, while the second one displays and functions correctly. I'm unsure about what went wrong in the code. Can someone please as ...

Loading of iframes occurs only after receiving the content sent through the postMessage function

I have a scenario where an iframe is used to receive information through the contentWindow.postMessage function in order to log in to a page that I am creating. However, I am facing an issue where the page loads before the contentWindow.postMessage message ...

What is the method to alter the fill of a circle using CSS when it is hovered over in JavaFX?

I am seeking assistance for a task involving a circle within an hBox. I would like the color of the circle to change when the mouse cursor hovers over it. Is there a way to accomplish this using JavaFX and CSS? If not, what is the recommended approach fo ...

Positioning of the dropdown in Material UI AutoComplete menus

Is there a way to turn off autocomplete auto position? I would like the autocomplete options to always appear at the bottom. Check out this link for more information! ...