Modernize your Mashups with CSS to enhance the presentation of your application.
This project will introduce using CSS to create a customized, consistent look and feel for your IoT application.
Following the steps in this guide, you will create a custom CSS class definitions and bind these classes to Mashup features.
We will teach you how to present a professional-looking user interface and ensure consistency of style treatments within your application by implementing Cascading Style Sheets (CSS) in Mashups.
You now have more flexibility to customize your application’s UI and improve the user experience using industry-standard web techniques. You can implement CSS in ThingWorx to control the visualization of your Mashup.
Feature Benefit
Text Treatments | Optimize text with shadow, color, font, and border |
Responsive UI | Customize layout based on user actions and the data being displayed |
Media Queries | Accommodate many screen sizes with flexboxes and other standard containers |
Animations | Implement standard CSS key frames |
Customizations | Modify application appearance without changing source Mashup |
Linting | Expedite development with code auto-completion and design-time syntax warnings |
We created sample entities you can use to complete the steps in this guide.
6. Select the CustomCssTutorialMashup.
7. Click View Mashup to view the Mashup.
NOTE: This is a simple Mashup designed to demonstrate how the UI changes when CSS is applied.
In this step, you will use the built-in editor to create a custom CSS class that will be used in the next step to modify the appearance of three buttons grouped by the Fieldset Widget.
.myMashupClass .widget-fieldset .widget-ptcsbutton { box-shadow: 5px 5px 5px #888888; }
NOTE: This class will create a shadow around all of the buttons that are in a Fieldset container only after it is bound to a Mashup,
4. Click Save.
Press Ctrl -> Space to use the Auto-complete feature and see code snippets, which can expedite your development time.
The Linting feature will warn you if there are errors in your code, so you can fix them at design time.
In this step we will demonstrate how to modify the look and feel of a Mashup without changing the Mashup itself. The myMashupClass we just created chains two selectors: the widget-fieldset and the widget-button. Only Widgets that are in both selector categories will be modified.
WARNING: You must press Tab after every property change in order for the new value to be saved.
4. Click Save then View Mashup to see that the buttons in the Field Set have shadow borders.
In addition to the Mashup level, you can apply style treatments directly to a Widget in your Mashup. In ThingWorx, the following Widgets have a CustomClass property you can modify:
For this example, we will make the text on one of the buttons all caps.
Add the following css code:
.myButtonClass .widget-ptcsbutton { text-transform: uppercase; }
The UI of a Mashup can be dynamically updated at runtime by binding the value of the CustomClass property to a dynamic data source such as:
In this portion of the guide, we will demonstrate modifying a Mashup in response to user actions:
.myBoundButtonClass1 .widget-ptcsbutton { text-transform: lowercase; } .myBoundButtonClass2 .widget-ptcsbutton { text-transform: uppercase; }
7. Click Save and then View Mashup.
8. Click on each of the Apply buttons to see the results of a CSS class applied to in response to user actions.
You can use Media queries to apply styling based on the characteristics of the device being used to access the application. For this example, we will use a CSS Class to hide three elements when the browser’s width is less than 600 pixels wide.
1. Open the CustomCssTutorialMashup in Edit and Design view, then click Custom CSS.
2. Copy the CSS class below and use the Custom CSS editor to add it to the top of the existing CSS, then click Save.
@media screen and (max-width: 1000px) { #root_ptcslabel-10-bounding-box { visibility: hidden; } #root_ptcstextfield-7-bounding-box{ visibility: hidden; } #root_ptcstextfield-12-bounding-box { visibility: hidden; } }
NOTE: The ID selector in your CSS must add root_ to the beginning, and -bounding-box to the end of the element’s ID shown in Mashup Builder.
3. Click View Mashup, then click and drag the edge of the browser window to reduce the width below 600 pixels.
NOTE: The three Widgets selected in the media class added in the last step will disappear as soon as the browser is less than 600 pixels wide.
Click here to view Part 2 of this guide.