Currently, I am working on a web part that requires some custom CSS files. To achieve this, I am utilizing the CssRegistration class to include them in the page header.
The implementation involves registering 4 CSS files that were deployed to the layouts folder through the web part feature. Additionally, a fifth CSS file can be registered based on a specified path in the web part's property AdditionalCss
. The requirement is for these CSS files to be appended after all SharePoint CSS files and maintain the order they were added in the code.
Below is the code snippet used for this purpose:
insert unique code here ...
Upon adding the web part to a page, all CSS files are successfully included. However, there seems to be an issue with the ordering of the files.
When there is no custom CSS file involved, the order is as follows: (link attributes removed for clarity)
...
<link href="/_layouts/1033/styles/Themable/corev4.css"/>
<link href="/_layouts/MyWebPart/css/colors.css"/>
<link href="/_layouts/MyWebPart/css/content.css"/>
<link href="/_layouts/MyWebPart/css/cn_custom.css"/>
<link href="/_layouts/MyWebPart/css/styles.css"/>
However, when introducing a custom CSS file, the order changes significantly:
...
<link href="/_layouts/1033/styles/Themable/corev4.css"/>
<link href="/_layouts/MyWebPart/css/cn_custom.css"/>
<link href="/sites/mysite/Style%2520Library/de-de/test.css"/>
<link href="/_layouts/MyWebPart/css/styles.css"/>
<link href="/_layouts/MyWebPart/css/content.css"/>
<link href="/_layouts/MyWebPart/css/colors.css"/>
The inconsistent ordering of CSS files poses challenges in maintaining design coherence. It appears that the CssRegistration class does not guarantee a consistent sequence, rendering CSS design an arduous task.