Hide text in modern page using CSS - SharePoint Online

George Thomas T P 1 Reputation point
2020-11-13T14:06:43.397+00:00

I have a modern SPO page and i want to hide the text "Add Link" using CSS. I found the class and used the below styles in Modern Script editor webpart to hide the text but it is not working:

Style 1:

<style type="text/css">  
.ms-HorizontalNavItem {  
display: none !important;  
}  
</style>  

Style 2:

<style type="text/css">  
  button.ms-HorizontalNavItem-link {  
  display: none !important;  
  }  
</style>  

Both style didn't work.Can someone tell me what i am doing wrong or how to achieve this?

39714-addlink.jpg

39687-addlink-html-element.jpg

Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. trevorseward 11,711 Reputation points
    2020-11-14T17:25:02.433+00:00

    Manipulating the DOM in SharePoint Online is not supported as the DOM frequently changes and any such solution would break. Instead, you should remove the user's permission which grants them the ability to add a link. By removing the permission, the add link should also disappear.

    0 comments No comments

  2. Baker Kong-MSFT 3,801 Reputation points
    2020-11-16T02:19:05.117+00:00

    Hi @George Thomas T P ,

    When the page is in edit mode, the style or elements may be different from when it's published. It seems that the style has not been embedded. Could you please generate the CSS selector through other attributes? Such as id tabindex?

    After saving the CSS code, please full refresh the page to load the CSS.

    39918-test.gif

    Best Regards,
    Baker Kong


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.