'ello!
I'm developing my first WebPart for Sharepoint, and now I'm wondering where/how to include/store my CSS. Where should I put my .css files? How should I include them in my webpart?
To enable this feature, visit Jetpack → Settings → Writing in your site's dashboard. Scroll down to the Theme Enhancements section and toggle on the Enhance CSS customization panel option. Starting with WordPress 4.7, you can now add custom CSS to your own theme directly from the Customizer.
This is my Approach
protected override void CreateChildControls()
{
CssRegistration.Register("/_layouts/STYLES/WebPartName/styles.css");
}
This ensures the CSS is registered and included only once and gives the opportunity to modify the CSS without redepolying the whole dll.
You should use Web Part Resources which can be linked or embedded. This article does a good job of explaining how to use them:
Best Practices for Managing Web Part Resources
U can also use:
HtmlLink linkCss = new HtmlLink();
//Defining attributes and values of the link tag
linkCss.Attributes.Add("href", "StyleSheet1.css");
linkCss.Attributes.Add("type", "text/css");
linkCss.Attributes.Add("rel", "Stylesheet");
//Add HtmlLink instance to the header of the current page
Page.Header.Controls.Add(linkCss);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With