How to apply or remove a CSS class
In TeleportHQ, you apply a CSS class from the Classes section of the right panel: select the element, type the class name and pick it from the list. The element takes on the class's styles right away. To take a class off, click Remove class (−) on the class's row. Removing a class from one element doesn't change the class or any other element.
Before you start
- Create the class first. See How to create a CSS class.
- You need a role that can edit pages. The Editor role can apply and remove classes, but can't create or edit them.
Apply a class
- On the canvas, click the element, for example your second product card. To apply the class to several elements at once, select them all.
- In the right panel, make sure the Visual tab is open.
- In the Classes section, click + at the right of its title. If the element already has a class, the search field is already there.
- Click the field and type part of the class name, for example
product. - In the list, click the class, for example
product-card.
The class shows in the Classes section as .product-card, and the element takes on its styles.
Check that it worked
The element on the canvas now looks like the other elements that use the class. In the right panel, style boxes show the class values in grey. Point at one to see Inherited from CSS class and the class name.
What's on a class's row
Each class on the element has its own row in the TeleportHQ Classes section:
- The checkbox turns the class off and on, on the canvas only, for a quick before-and-after look. The class name is crossed out while it's off. This isn't saved: the class is back on when you reload the project, and your published site always uses it.
- Edit class opens the class's styles. See How to edit a CSS class.
- Remove class (−) takes the class off this element.
- Add rendering condition (an eye with a small C) applies the class only when a condition is true. See How to show or hide elements based on a condition.
The + between Remove class and the eye adds a combinator to the class. See How to style elements inside a class (combinators).
Remove a class from an element
- Select the element.
- In the Classes section, on the class's row, click Remove class (−).
The class is removed from this element right away, with no confirmation. The element loses the class's styles. The class itself, and every other element that uses it, stays the same.
Remove all classes from an element
- In the Classes section, click − at the right of the section title. It replaces the + once the element has a class.
- In the Remove Classes from node window ("You are about to remove all classes from the node"), click Remove.
This works on one element at a time.
Troubleshooting
The class is applied, but one style doesn't change The element has its own value for that style, and the element's own styles win over classes. Clear the value in the right panel to use the class value. Or, to make the element's change part of the class, open the class with Edit class and click Extract new styles. See How to edit a CSS class.
The class doesn't appear in the search list Classes already on the element aren't listed again. The search also matches capital letters exactly: type Card to find Card, not card.
My element changed when I edited it, but other elements with the same class didn't Style changes made in the right panel go onto the selected element, not into the class. Edit the class itself to change every element. See How to edit a CSS class.
"Your current role does not have permission to add or update classes" Your role can apply classes but can't open them for editing. Ask a workspace admin for a role that can change CSS classes.
Good to know
- An element can have several classes. They're listed in the Classes section. If two of them set the same style, see What are CSS classes, and why use them?.
- To see every element that uses a class, open the Classes tab of the Design Language panel, right-click the class and choose Highlight linked nodes or View linked nodes.
- The layers tree shows each element's classes next to its name. To hide them, click the Project settings cog at the bottom of the left sidebar, then Editor → Preferences → View, and under Layers turn off CSS classes in the tree view.