Replies: 4 comments 14 replies
|
Why would you need JavaScript to change the list from horizontal (li set to display: inline) to vertical (li set to display: block)? That can live in your viewport-specific part of the CSS, along with the visible hamburger etc.
Walter
… On Apr 2, 2023, at 9:22 PM, bjazmoore ***@***.***> wrote:
I started playing around with making the NAV work responsively. I was able to hide the menu items and slap on a hamburger menu. Obviously I would need some Javascript to make the UL/LI menu items display as a stacked menu item. I thought about slapping an ASIDE tag into the NAV, but that does not seem to do what I want. My extra CSS and custom classes started getting really complex and I thought "this is not the Pico.css way".
Anyone have some examples? I can post my code if you want it.
Thanks
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
|
|
@bjazmoore you need neither JS nor an nav, nav ul {
flex-direction: column;
}
@media (min-width: 576px) {
nav, nav ul {
flex-direction: row;
}
}Here's a sample of it in action. This will make both the Note that I used the latest version as of date (v2.0.6). It works for any version that sets As for the burger menu, you can create one with its toggling effect in plain CSS using a styled label + checkbox input + rules that depend on Here's another sample that contains the responsive nav, burger menu to toggle menu items on narrow viewports using the latter approach and some animations to make it smooth. P.S.: Sorry to necropost, I only started using pico.css a week ago and I ended up looking for a potential pre-built way to enable this, leading me to this question and solution. Cheers! |
|
You cannot make it responsive without code duplication without using some sort of JavaScript. If you want a JavaScript-less approach, you can leverage the dialog component with a checkbox hack with minimal CSS. Just keep in mind that this would require you to duplicate the content of the menu: Demo: https://jsfiddle.net/2ya1k9st/ |
|
An alternative, no-JS approach, would be to leverage the details element. This can leverage the <details role="menubar" aria-labelledby="menubar-title">
<summary>
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="currentColor" aria-hidden="true" focusable="false">
<path d="M120-240v-80h720v80H120Zm0-200v-80h720v80H120Zm0-200v-80h720v80H120Z"/>
</svg>
</summary>
<nav aria-label="Website navigation bar">
<ul aria-label="Brand name">
<li role="none">
<strong>Acme Corp</strong>
</li>
</ul>
<ul aria-label="Navigation">
<li role="none"><a role="menuitem" href="#">About</a></li>
<li role="none"><a role="menuitem" href="#">Services</a></li>
<li role="none"><a role="menuitem" href="#">Products</a></li>
</ul>
</nav>
</details>details[role="menubar" i] > summary::after {
display: none;
}
details[role="menubar" i] > summary > nav,
details[role="menubar" i] > nav > ul {
overflow-x: auto;
}
details[role="menubar" i] > nav,
details[role="menubar" i] > nav > ul {
flex-direction: column;
}
details[role="menubar" i] > nav > ul > li {
flex: 0 0 auto;
}
@media (min-width: 576px) {
details[role="menubar" i] > summary {
display: none;
}
details[role="menubar" i] > nav,
details[role="menubar" i] > nav > ul {
flex-direction: row;
}
details[role="menubar" i]:not([open])::details-content {
content-visibility: visible;
}
}Demo: https://jsfiddle.net/97x5fotz/ |


Uh oh!
There was an error while loading. Please reload this page.
I started playing around with making the NAV work responsively. I was able to hide the menu items and slap on a hamburger menu. Obviously I would need some Javascript to make the UL/LI menu items display as a stacked menu item. I thought about slapping an ASIDE tag into the NAV, but that does not seem to do what I want. My extra CSS and custom classes started getting really complex and I thought "this is not the Pico.css way".
Anyone have some examples? I can post my code if you want it.
Thanks
All reactions