I have a website that uses responsive CSS. Depending on the responsive state, I want to change the menu:
- The site is displayed on a wide screen, thus I have a two column design. In this mode I can make use of the complete height of the screen, so I can have a list of categories and tags under a headline, which takes quite some space.
- The site is displayed on a less wide screen, which stacks everything into one column. In this mode I want to add a link to category and tag overview to the menu rather than keeping the longish list of tags and categories.
My recent approach is to use two CSS classes, horizontal and vertical:
@media (min-width: 801px) {
.vertical { display: none; }
}
@media (max-width: 800px) {
.horizontal { display: none; }
}
These classes are used to decorate the two menu items for category and tag overview as well as the category and tag lists below the menu.
[EDIT]: To simplify the code, I only put the category, tags are equivalent. I fear I have missent some readers (sorry!), so I added more code to clearly show the difference between the two options.
<head>
...
<meta name="viewport" content="width=device-width, initial-scale=1">
...
</head>
...
<aside>
<nav class="nav">
<ul class="list-bare">
{% for title, link in MENUITEMS %}
<li><a class="nav__link" href="{{ link }}">{{ title }}</a></li>
{% endfor %}
<li class="vertical"><a class="nav__link" href="/categories.html">Categories</a></li>
</ul>
</nav>
<h2 class="horizontal">Categories</h2>
<ul class="navbar horizontal">
{% for cat, null in categories %}
<li{% if cat == category %} class="active"{% endif %}><a href="{{ SITEURL }}/{{ cat.url }}">{{ cat }}</a></li>
{% endfor %}
</ul>
</aside>
This actually works. But I'm wondering if this is state of the CSS art. Or is there another mechanism to do those alternating things?