2018-10-25 Web Design for Simpletons

As mentioned before, I now have two static sites generated by a *Planet*, Old School RPG Planet and Indie RPG Planet. I wanted these pages to be easy to read from a phone. How to do this?

Old School RPG Planet

Indie RPG Planet

Screenshot of how it looks on wide screen

The first step is to add a viewport meta element. Don’t ask me why this is necessary. What were mobile browser makers thinking?

I added this to the HTML:

Next, I wanted the unnumbered list with all the members to be hidden by default, and to show or hide it with a click. The simplest solution (to a simpleton like me) is to use a class attribute on the element I want to toggle.

Thus:

And some Javascript to toggle it:

I call `addMenu` when the page loads. It identifies the ā€œMembersā€ heading (the first `h2`) which will be used as a button and it identifies the actual list of members (the first `ul`) which will be toggled. Toggling simply means changing the class attribute from ā€œhiddenā€ to ā€œshownā€ and back. Everything else happens in the CSS.

As you can see, I’m setting a few borders and paddings to smaller values or to zero in order to not waste any space, and most importantly, the `display` property of the list changes depending on the class attribute.

All of this is wrapped in a selector for narrow screens, which in this case means anything less than 1000px wide. Which you trigger on the Desktop by simply making your browser window narrow.

Screenshot on a narrow screen

Also, if your Javascript is disabled, the list is hidden and remains hidden. I think that’s a good default.

And in a text browser, the list is present. But it’s OK because there’s a ā€œSkip to contentā€ link at the very top.

Screenshot of w3m

​#Web ​#CSS

Comments

(Please contact me if you want to remove your comment.)

⁂

@tomasino offers a different solution without JavaScript using a checkbox and the `:checked` pseudo class. He posted a codepen demo, too. Thanks!

@tomasino

codepen demo

And I used it for the two Planets,too!

The HTML now looks as follows:

And the CSS stripped down to its essentials looks as follows:

In a text browser, the checkbox remains visible:

For browsers without CSS support, the useless checkbox remains visible, of course.

– Alex Schroeder 2018-10-25 20:17 UTC