I am coding a responsive website (say one breakpoint so everything is ok) and it will look like this:
Wide screens:
HEADER
HERO
NAV | SEARCH
Narrow screens:
HEADER
NAV | SEARCH
HERO
As you can see, this is not just about CSS and media queries. There is some restructuring of the DOM. Obviously, this is a simplified example, and it may make sense to serve completely different HTML files depending on the size of the viewport.
But ... what if the code is 90% identical between widescreen and narrowscreen versions? Of course, it is not recommended to duplicate all this code when only a few elements move in the DOM tree.
My approach right now:
<header>...</header>
<section class="hero">...</section>
<section class="controls">
<nav>...</nav>
<form class="search">...</form>
</section>
<script>
if(viewport.width < 768){
$('.controls').insertAfter('header');
}
</script>
jQuery, . .
?
: , display: table . . flexbox, , .