質問

I am designing a mobile website. On the homepage i have menu items say 'a' ,'b' ,'c',...,'h'. I want to display only first three menu items and make a 'View All Items' button that on clicking expands to show all the items.Also the button should become 'Show Less Items' after clicking on it.

I want to do this using only HTML5 and CSS3 and no JavaScript. Also i want this functionality to be reusable around the website.

How should i do it?

--Thanks in advance!

役に立ちましたか?

解決

Modern mobile browsers all support JavaScript, but give end users (at least in Android's case, not sure about iOS) a configuration setting to disable it.

Your best bet as a developer is to use the "fail safe" strategy: Ship the HTML with the menu fully expanded, and use JavaScript to collapse the menu immediately on load (or on DOM ready). That way, if you have mobile users with JavaScript disabled, they will see the whole menu. Most of your users should have JavaScript enabled, in which case they will get the expand/collapse functionality you describe.

他のヒント

It's unrealistic to expect to implement this without JavaScript, and if you can find a workaround I don't believe it to be as stable as simply using JavaScript. In terms of hiding the menu items you could set their CSS property to display: none; and place a button which targets these menu items and toggles their display property.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top