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?
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.
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.
ā#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!
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