Sep 21 2021 09:03 AM
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?
Sep 22 2021 05:10 AM
@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.
Sep 22 2021 07:22 AM
Jan 22 2024 06:16 AM
Feb 15 2024 01:17 PM
@Fredrik_Fjllstrm Can you post an example of how to do this? I'm having the same issue.
Thanks so much!
Feb 26 2024 01:36 PM
@mcads I wondered that exact question myself and asked Microsoft Copilot. Here's what it said:
Certainly! To conditionally hide an element within a SharePoint Online page using CSS, you can create a custom CSS class with the property display: none. Then, apply this class to the desired element based on specific conditions (such as whether a web part is empty). Here’s how you can achieve this:
Create a Custom CSS Class:
.custom-hidden { display: none; }
Identify the Element to Hide:
Apply the Custom Class Conditionally:
Example Usage:
<div id="myElement" class="custom-hidden"> <!-- Content of the element --> </div>
Content Editor Web Part (Classic):
Modern Pages:
Remember to adjust the class name (custom-hidden) and the element ID (myElement) according to your specific use case. Additionally, consider using the appropriate method based on whether you’re working with classic or modern SharePoint pages. :globe_with_meridians::artist_palette:
References: