Applying Clarity's Global and Scoped Styling
A key part of creating a polished application is applying custom styles that enhance its usability and align with your brand. With client extensions, you can apply both component-scoped and global CSS. Clarity wants to use these client extensions to improve the visual styling of their distributor locator app and establish consistent brand styling across their website.
In this exercise, you’ll use client extensions to apply both component-scoped and global styling.
Exercise: Adding Styling to the Distributor Table Component
Clarity wants to improve the styling of their Distributor Table component to make the data easier to read and visually distinct. Here, you’ll modify the Distributor Table custom element’s CSS files and redeploy the client extension.
-
In your file explorer, go to the
client-extensions/clarity-distributor-table-custom-element/src/folder, open theApp.cssfile, and analyze it.
This file contains the React app’s CSS styling. Notice theclarity-distributor-table-custom-elementelement reference at the top and the styling within it. -
Below the
.logoclass block, insert a new line and add this:table { } -
Within the
tableblock, include these styles:Style
Value
width100%border-color#89A7E0border-width1pxborder-stylesolidThis ensures the table is always full-width and adds a light blue border around it.
-
Add a
thblock nested within thetableblock and include these styles:Style
Value
text-aligncenterheight3remThis aligns the header text in the center of the table cell.
-
Add this below the
thblock:tr:nth-child(even) { background-color: #EEF2FA; }This adds a different background for alternating table rows. With the Distributor Table styling finished, you can redeploy the client extension to apply your changes.
-
Save the file.
-
In your terminal, go to the
client-extensions/clarity-distributor-table-custom-element/and deploy the client extension. -
In your Liferay instance, go to the Distributor Details page to see the new table styling.
Great! You’ve successfully added component-scoped styling to Clarity’s Distributor Table custom element. Next, Clarity needs to apply their brand styling to their entire website.
Exercise: Deploying Clarity’s Theme CSS Client Extension
Here, you’ll explore and deploy a theme CSS client extension containing Clarity’s official styling.
-
In your file explorer, go to the
exercises/module-2/and find theclarity-theme/folder.
This is Clarity’s theme CSS client extension. It was built on top of Liferay’s out-of-the-box Dialect theme. -
Take a moment to explore its content and style files.
-
Move the
clarity-theme/project into theclient-extensions/folder of your course workspace. -
In your terminal, deploy the
clarity-themeclient extension and verify it's successful.INFO [fileinstall-directory-watcher][BundleStartStopLogger:68] STARTED claritytheme_7.4.13 [1489]With the client extension deployed, you can apply the styling to Clarity’s website globally.
-
In your Liferay instance, open the Site Menu (
), expand Site Builder, and click Pages.
-
Click Actions (
) on the Application Bar and select Configuration.
Notice that Dialect is the selected theme. This allows the theme CSS client extension to leverage Liferay’s predefined classes and styling variables. -
Scroll down to the Theme CSS Client Extension section.
-
For Theme CSS, click Add (
) and select Clarity Theme CSS.
-
Scroll down and click Save.
This applies the theme CSS client extension to Clarity’s website. -
Go to the Distributor Details page and verify the new styling.
Great! You’ve deployed Clarity’s theme CSS client extension and applied it to their website, providing a unified visual experience.
Conclusion
Global and scoped styling are effective methods to ensure consistent branding across multiple pages and web applications. By applying these methods strategically, you can deliver unified, smooth digital experiences.
Next, you’ll learn how to implement responsive design in your applications.
Capabilities
Product
Education
Knowledge Base
Contact Us