(CSS) Reversing the order of Grid elements
The following code will turn a two-column grid layout into a single-column one when viewport width falls under 760px :
.grid {
display: grid;
width: 100%;
grid-template-columns: 50% 50%;
grid-column-gap: 1em;
grid-row-gap: 1em;
}
.grid span { width:100% }
@media screen and (max-width: 760px)
.grid { grid-template-columns: 100% }
}
<div class="grid">
<span>Hi</span>
<span>Bye</span>
</div>
What's the least amount of code required to flip the order of "Hi" and "Bye" when the page switches to a single-column layout (ie, < 760px)? No need to worry about where a 3rd element would fall, it should always just be 2.
Ideally, I'd like to do this using existing selectors like :first-child (perhaps making it float:right on the resize would make it appear last) but if that's too much of an ask, I'd be open to assigning an ID to one or both of the spans. I'm also told Flexbox will reverse order easily without requiring ID tags; but if Grid does it too, I'd rather stick with that since I'm already using it.
Thanks!
