JavaScript – Toggle CSS code on / off depending on whether the element is visible or not

  • Home / Blog / JavaScript – Toggle…

JavaScript – Toggle CSS code on / off depending on whether the element is visible or not

I am in the process of creating a top bar with HTML and CSS. It seems:

<div class="topbar">

    <nav class="container">
         <div class="text1">Text</div>
    </nav>

    <nav class="container">
         <div class="text2">Text2</div>
    </nav>

    <nav class="container">
         <div class="text3">Text3</div>
    </nav>

    <nav class="container">
         <div class="text4">Text4</div>
         <div class="text5">Text5</div> <!--This is triggered by an external 
         Javascript code, it is sometimes visible and sometimes not visible. -->
    </nav>

</div>

I have added CSS to make the code responsive with a flex element.

@media screen and (max-width: 820px) {
nav.container   {
flex-grow: 3;
}
}

The only thing I’m missing right now is a code, which disables the CSS code when Dave (Text5) doesn’t appear above.

Write a Comment

Your email address will not be published. Required fields are marked *

x