question

BilalZaman20-6535 avatar image
0 Votes"
BilalZaman20-6535 asked DSPatrick edited

How can I save CSS-code in SharePoint?

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:

 <style unselectable="on">
 </style>

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-supported
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DSPatrick avatar image
0 Votes"
DSPatrick answered

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.







5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.