6a. Tabbed Content Take 2

Page section: playground

section 1

Two functions are created. The first removes the class of active from all the li elements in the nav bar. The second add the class of hidden to each section.

The next and main part of the script loops through the 3 list items using a forEach() method. An event listener is added to each li and when a click event is fired several things happen ...

The fixes

There were 2 main fixes. The first was to stop scrolling from using anchor tags. So I stripped the anchor tags away. The second was to stop the height of the container changing as the content changed. Fixed using grid and visibility: hidden.

So the first version of this CodeBubb mini project worked as it was supposed to but not very well I thought. The problem with using hyperlinks to access the tabs might be good semantic HTML but causes the whole box to move accross the screen, sometimes wildly, depending on the viewport size.

Another problem was that if the content of each section was of different lengths then the size of the container, div.tabbed-content, changes with every click.

My first thought was to try changing the .hidden class from display: none to visibility: hidden. This hides the section element rather than removing it completely. This left the sections exactly as they were which is running down the page.

To prevent this I set all the article content to display: grid. I defined one grid-template-area and called it content:

article {
    display: grid;
    grid-template-areas:
    content;
}

Then I put all sections into one another