I've been trying for hours to setup the following layout with html and css (and Bootstrap, if needed):
That is:
- For desktop, the card (or whatever element) should be floating on the right
- For mobile, the card should be positioned below the text
The problem with using just float: right is that the floating element should be positioned in the html before the text, but in mobile the element will be displayed on the top of the text, and I wanted it at the bottom.
Surprisingly, I was not able to find any existing question (maybe I just did not use the proper keywords). The most similar question I found was CSS floats, change order on mobile layout?, but it is not really the same problem.
The first idea I had to solve it was to just use Bootstrap's column system, but if the height of the text element is larger than the floating element, it will stay in the same column and not continue below the floating element.
I eventually found a solution (which I will post as an answer), but since it took me so long to figure it out, I thought I will create a question anyway to save time to others that face the same issue. Plus probably somebody will propose a better solution than mine.