How can I save CSS-code in SharePoint?

BilalZaman20 1 Reputation point
2020-06-04T08:24:08.497+00:00

Hello,

I'm trying to use CSS-code in order to change the appearance of a webpart in SharePoint 2013 on-premise. But SharePoint Always discards the code. How can I save the code permamently? Or how can I change the appearance (like colors and fonts) of my webparts?

Here's what I tried so far:

EDIT SOURCE

  1. Edit page, edit source, add these lines on the very top (ps: below there already is some html-code, like <h1>Welcome</h1>): <style>
    #WebPartTitleWPQ3{
    background-color: red;
    }
    </style>

After pressing "OK", the titlebar of my webpart is red. After saving the page, the red color is gone, so is the code I added. What's left of my code added is <style></style> [the html-code is still there, of course].

  1. Edit page, edit source, add these lines on the very top: <script type="text/css">
    #WebPartTitleWPQ3{
    background-color: red;
    }
    </script>

After pressing "OK", SharePoint immediately tells me, that some of my markups have been removed, I should try and use embedding. My code is deleted immediately.

  1. Edit page, edit source, add these lines on the very top: <style><script type="text/css">
    #WebPartTitleWPQ3{
    background-color: red;
    }
    </script></style>

After pressing "OK", there is no error-message, but the titlebar of my webparts isn't red either. After saving the page, my code is gone except for <style></style>.

  1. Edit page, edit source, add these lines on the very top: <style>
    </style>
    <script type="text/css">
    #WebPartTitleWPQ3{
    background-color: red;
    }
    </script>

After pressing "OK", SharePoint immediately tells me, that some of my markups have been removed, I should try and use embedding. After saving the page, my code is gone except for <style></style>.

EMBED CODE

  1. Edit page, insert, embed code, insert these lines [ps: before adding my lines, the embed-code-windows is empty]: <style>
    #WebPartTitleWPQ3{
    background-color: red;
    }
    </style>

The titlebar of my webpart immediately turns red, as soon as I enter the code. After saving the page, the color of my webpart is gone. The code has been changed into:

&lt;style unselectable=&#34;on&#34;&gt;
&lt;/style&gt;

Trying to add the lines #WebPartTitleWPQ3... in beetween the <style>-brackets, turns the titlebar of my webpart immediatley red, but after saving the page, the code is gone again.

  1. Edit page, insert, embed code, insert these lines: <script type="text/css">
    #WebPartTitleWPQ3{
    background-color: red;
    }
    </script>

This changes the webpart-type of the embedded code (from something like "snippet" into someting like "script-editor"). The titlebar of my webpart doesn't turn red, the script-editor-webpart doesn't show something like "edit code", so I cannot see, what's left of my code. I can only delete this new script-webpart.

CHANGE SHAREPOINT SECURITY

  1. I opened the central administration of my SharePoint and edited the securitysettings for webparts: allow Contributors to add or edit scriptable web parts - on. I repeated all the steps above. No changes there. I don't know, if the change of security-settings needs some time in order to work.

Best regards,

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,459 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Dave Patrick 426.2K Reputation points MVP
    2020-06-04T11:29:51.443+00:00

    Sharepoint is not currently supported here on QnA. I'd try asking for help in dedicated forums here.

    https://social.technet.microsoft.com/Forums/sharepoint/en-US/home?category=sharepoint

    --please don't forget to Accept as answer if the reply is helpful--


    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    0 comments No comments