Forum Discussion

smithme's avatar
smithme
Copper Contributor
Sep 21, 2021

HOW TO: Hide web part when it's empty

I have a web part I wrote that I want to hide when there is no content in it (like the News web part). How do I do that?

5 Replies

  • shinypurple's avatar
    shinypurple
    Copper Contributor

    smithme There's usually an option to hide the web part if there's nothing to show. It's definitely on 'News', although maybe not on every web part.

     

     

    • smithme's avatar
      smithme
      Copper Contributor
      Sorry, I wasn't more clear. I am writing a custom webpart. I want it to take up zero vertical space on the page when it is empty. How do I programmatically, tell my webpart to display:none;
      • Fredrik_Fjllstrm's avatar
        Fredrik_Fjllstrm
        Copper Contributor
        I would add a CSS class of hidden that only has display:none and add that class to whatever element I want to hide if the webpart is empty.

Resources