Skip to main content
Sticky CSS Guidelines for CC

Custom CSS Guidelines for Customer Communities

  • 25 June 2024
  • 0 replies
  • 205 views
Custom CSS Guidelines for Customer Communities


Introduction

Welcome to our Custom CSS Guidelines! We’re here to help you create beautiful and functional custom styles in Gainsight Customer Communities. These guidelines introduce structured conventions to mitigate the risks associated with broken CSS. Following these guidelines ensures your custom CSS is robust, reliable, and compatible with our platform.

Our approach involves introducing new anchor points strategically designed to facilitate the creation of cleaner CSS code. These anchor points serve as reference markers, enabling you to adopt a more organized and systematic approach to styling. By incorporating these anchor points into your CSS structure, you can effectively address challenges posed by global CSS inconsistencies. This approach not only enhances the overall stability of your custom styles but also empowers you to develop confidently knowing that your CSS will be less prone to issues stemming from conflicting styles or unintended overrides.

 

Begin with overriding CSS Variables

Using CSS variables is a resilient method for applying custom styles because it allows you to change properties like colors, borders, and border-radiuses without directly targeting HTML elements. This approach reduces the risk of your styles breaking when there are changes to the underlying HTML markup.

We use CSS variables as a foundation for Theme Customization functionality. You have more granular control and more options by changing CSS variable value compared to available customization using UI of Theme Customisation.

 

Examples

 

Always Start Your Styles with Specific Identifiers

TL DR: Make sure your CSS Specificity is more than 200

To ensure that your custom CSS does not interfere with our existing styles and to prevent CSS specificity issues, always use the following identifiers at the beginning of your styles:

#customcss #root .your-css-selector {

/* Your custom styles here */

}

Using these two identifiers (#customcss #root) will ensure that your code is required and has sufficient specificity. It also allows you to avoid adding extra class names to the CSS selector and gives us more flexibility in terms of HTML markup changes.

If you encounter any crucial rules or CSS specificity issues caused by our code, please report them to our support team via an assistance ticket.

 

Examples:

AD_4nXfFxbRSFuqdQWAJ1EFlJmjhgGEdH2y0CqpRVS4Ukov9Zu1Ax2IphjIxL6VKu9axI5f5BVqYRyenQ3yYzBCpr_-4TKqczQCKP55xzDWAPE_4ushXOZ-3xLkTq80pDvCIVlvbJVM1q07neT05TEZT1yUSJ8jL?key=p9P54G7wqcCc5DncjchJEA

AD_4nXejjURKUhroN5hNCUOsQDvrv7pwPJLR65q2flDi53X51Bl0WR0FW-jACjXNsd8-2AcC3reRYcEeiAQ8tU1LQfobUvkY0wH-E_K5FxZgdZuYKJLcrO3-WPOO6Y6vAkmfsmR4Lhv_SRALjOaL3kovg0QkUPp6?key=p9P54G7wqcCc5DncjchJEA

Links:

 

Use 2data-css-anchor] Attributes in Your CSS Selectors as Anchors

 

TL DR; Scope your styles using #customcss #root sdata-css-anchor="%name%"] to prevent global CSS errors.

 

We are introducing the use of data-css-anchor attributes to represent actual modules in the codebase or product features. This change provides a more reliable and stable way to target elements in your custom CSS. Here's how you can effectively use data-css-anchor attributes for styling:

 

Links

 

Avoid Using ~, >, and + Operators; Prefer the Descendant Combinator (Space Selector)

 

To keep your CSS simple and avoid specificity issues, avoid using sibling (~), child (>), and adjacent sibling (+) combinators. Instead, prefer using the descendant combinator (space selector).

It gives us more flexibility in terms of HTML markup changes without breaking Custom CSS styles.


Examples:

AD_4nXfBFczeUCtah0zcq4N25q0l1f8Zl7Nc-fzEqdNIgcVV9Er29BH9Un6GvvnraFZGjxnBEHw7dp6MGhtrtJp9z17D3YgKkc5kBKW9uADTtNVmw0g7xyaDCBgyqKGT2FYwUAbnDnH-zqZSXQxzTxpjUQQW5PvG?key=p9P54G7wqcCc5DncjchJEA

Links:


Avoid Manipulating DOM for Styling

 

Gainsight's strict recommendation is that your CSS or scripts should not change the DOM.

Manipulating the DOM, such as adding or removing classes or attributes from HTML elements, can lead to inconsistencies and conflicts outside of our control. This makes it harder for us to support and update the UI elements without impacting highly customized communities.

Do’s and Don’ts:

  • Do: Use existing classes and data attributes as selectors in your CSS to ensure a cohesive and consistent user interface.
  • Don’t: Add or remove classes or any other attributes from HTML elements.

If you have any questions or need help, our onboarding and support team is here to help! We encourage you to reach out for any assistance you may need during your CSS customization process.

 

Examples:

 

AD_4nXcnufsYDLWXE-konGjuY-0YGIq13xV1ayhTGAx0j4iPOgVM-96m4VMJxxw2y1Kd1TFlDLgKiE0xPb_xBZvXw0wBw0jiFdwEquV_y0Dd1VmKacYe9Qop-FAH0JKObrZ10akmM8WR8c-MnPRbuqOfXGBp8BE?key=p9P54G7wqcCc5DncjchJEA

More examples of good practices.

 

AD_4nXe34L4DQt8DOwyf0DLsMvo9_auijNSJRQst6d3j_LUw4gk3dLeXXgfUfFpQpElmY5OmIGSFa5jTaQZJ1wuy3YF1ab0ZYuI94ekh1pcGUbPdejV-dujVt9mwAzyQuBo3DnVCSMZH-DcseE2GUozWsVVLarE?key=p9P54G7wqcCc5DncjchJEA

 

If you’re using preprocessors, you can simply nest it in the following way:

 

AD_4nXeT0DyTmUMCFIr9L8NAh1KNSywvoEisHDt-ya26VlU1l6XKN0nJkXKdZkmYtr-M-U3tbenDQwmsgaDsHjsu_39VzpBOgriovDFoKzIXvlUilxoaq1wrKpXfSdpNN8L9zmykGosoyCnrUMsIw23WGXvi278?key=p9P54G7wqcCc5DncjchJEA

 

 

0 replies

Be the first to reply!

Reply