Day # 5: Accordion
For this day I decided to create an accordion, which is a feature that is very useful when it comes down to displaying information that can also be hidden. Accordions are typically used for FAQ, so it is really helpful to be able to create them for websites that are transmitting information that can lead to some doubts.
This particular website was made with only HTML and CSS, since I wanted to explore the capacities of the latter language in regards to showing dynamic content.
The key here was to use an input[type = “radio”], since it allows me to only show one piece of information at a time, since this type of input gets to hide the others that are not “checked”. To achieve this, I set the max-height of the div that contains the information to “0”, and once the input is checked, then the max-height value changes to 400px. In other words, once you click on the input the content gets shown.
Lastly, I also wanted to highlight the fact that I added a transition to the max-height property, i.e. for when that content is displayed, since it is very important to show this change in an elegant way. Keep in mind that, as frontend developers, we always need to take care of the way in which those transitions are being shown to the viewer.
Comments
Post a Comment