Reverse element positions on mobile - Quick tip!

Have you ever set up a design like this in the editor where you want the #2 content to show on the right in Desktop view but then have it show on top in Mobile view?

The normal behavior you’ll get from Bubble (as shown below) is typically what you need. But how can you change this behavior when you really need to reverse the element positions on the small screen?

Normal element behavior

One way to change this behavior is to add another element with the content of group 2 and use conditionals to hide/show the correct group based on screen size. But then you have to maintain two identical elements which can be a pain :hot_face:

Fortunately, it can be easier than that! Here’s how :slight_smile:

Step 1 - Make sure the #1 and #2 groups are grouped together and nested inside a single parent group.

Step 2 - Add a unique ID to the ID Attribute property in the parent group’s property editor.

Screen Shot 2020-10-31 at 2.31.01 PM

Step 3 - Add the following code to the page HTML header. Make sure the ID is the same as the ID of your parent group!

<style> 
#elementContainer {
display: flex;
flex-direction: column-reverse;
justify-content: center;
}            
</style>

That’ll look like this in the property editor for the page

Screen Shot 2020-10-31 at 2.31.52 PM

Voila! The new responsive behavior for your groups!

Revised element behavior

Good luck!

Eli

44 Likes

Great, well done!

1 Like

Funny, I’ve been wondering how to do this for months now. Great tip @eli!!

Hi Eli

Great tip! Do you have any idea how to do this with 3 items - specially the problem is that the 3 items must transition from being on the same row to being in a single column at the same instant.

Bubble’s native behaviour appears to be that the last element will move to the next row, then as the screen is resized, the 2nd element will move to the next row, pushing the last element to the 3rd row.

I’m instead looking for something like this. Can the CSS be adapted?
https://www.w3schools.com/code/tryit.asp?filename=GLL9WXIS4DVQ

Thanks in advance!

1 Like

I worked! I screwed it up the first time because I put the ID on group #1, not the parent.

I’ve tried this multiple times, but it hasn’t been working for me.

  1. I’ve grouped items #1 and #2 together and nested inside a single group
  2. I’ve added a unique ID to the attribute property to the parent group
  3. added the page HTML header in the current page

Not sure what am I missing…? Thanks

Where do I set the ID Attribute from? I’ve checked almost everywhere.

Hey @bestbubbledev !

You can set an ID Attribute from the bottom of your Properties page, as shown here:

That option is not there?

No worries. Go to Settings > General > General Appearance > Check the box that says “Expose the option to add an ID attribute to HTML elements”

As shown here:

1 Like

Just did that! Thanks. Sadly it doesn’t work for me. What are the standard issues of this thing not working?

@gio.kakhiani
Can you make a copy and share the page and make the editor viewable? That will make it much easier to diagnose the problem.

Updated CSS for the new responsive engine:

<style>
#elementContainer {
    flex-direction: column-reverse;
}

#elementContainer > div {
    min-width: 100%!important;    
}
</style>

CleanShot 2021-11-15 at 17.06.40

9 Likes

Thanks for posting this update @eli

I was having an issue with it and was not sure what I was doing wrong.

When I don’t have the code on the page I have a preview that looks like this on a device width larger than 1600px.

And when collapsing the page it looks like this. The collapse is as expected since the groups left and right have min width set to 300px each and the page is 599px in the screen shot below (the moment the break lines).

However, if I put the code on the page my preview looks like this on the device width larger than 1600px

I was expecting that utilizing the code wouldn’t force them to break lines immediately and would just reverse their position when the lines break. That was the experience I had with the code you shared for the original responsive engine.

What seems to be happening because of the min-width of 100% setting on the elementcontainer div it is stretching to fit the entire viewport width. Also seems like the new responsive engine is reversing the position immediately.

To fix for this I put a conditional onto my HTML to only use the code after the page width has passed the ‘line-break’ point.

Screen Shot 2021-11-16 at 1.27.37 PM

Previously this was not needed. Do you think it is an issue with the new responsive engine that causes it to reverse immediately?

2 Likes

Hey Matt,

This is actually correct behavior. Setting the the flex-direction (i.e. column-reverse) will impact the elements regardless of the screen width. In this particular case, it is the same as converting the group layout to ‘column’ at the wider width (which is why the elements are stacking) and reversing them (why the positions are reversed).

When writing CSS you would use media queries to specify which CSS should be used at different screen sizes. We can apply that to this code like this:

<style>
@media only screen and (max-width: 800px) {
    #elementContainer {
        flex-direction: column-reverse;
    }

    #elementContainer > div {
        min-width: 100%!important;    
    }
}
</style> 

The max-width is telling the browser to only use the styling from this CSS code when the page width is < 800px.

Your conditional is a visual alternative to the @media query that would be used in a stylesheet. It all looks good!

5 Likes

Thanks Eli for that insight. This is definitely going to help me when trying to put together other CSS for use in the new responsive engine.

1 Like

I have tried this with the new responsive engine and can’t get it to work. Does anyone have any suggestions or workarounds?

1 Like

Initially I couldn’t get this to work with the new responsive engine or after upgrading. However, through a process of trial and error I managed to find a solution that worked. But if anyone can shed light on why there is a discrepancy between the responsive editor and rendered page I would love to hear your thoughts.

Here’s a video of the solution and the responsive editor issue [Bubble.io - Reverse element position at break point - VEED].

I would love to hear your thoughts and hope this helps anyone that hasn’t managed to get it working so far.

2 Likes

On another forum Matt Neary provided a little insight. He said:

The reason it doesn’t fold upwards in Bubble’s native responsive viewer is that the custom CSS styling which creates the reverse behaviour is only injected into your page when it loads. Bubble’s native viewer doesn’t pick up on this code. The custom CSS essentially overrides the CSS that Bubble generates, but only when your page loads in the browser.

Hope this helps.

This does not seem to be working for me. I’ve tried all solutions on this thread, including using HTML element vs. in header, conditionally setting the HTML or the ID Attribute based on width, etc.

Is this still functioning for anyone on the newest version of responsive? Or does anyone have a currently working solution?

Is this still not natively possible with the new responsiveness engine?

Thanks boss!