CSS classes

How to style elements inside a class (combinators)

How to style elements inside a class (combinators)

In TeleportHQ, a combinator styles elements based on where they sit compared with a class. For example, .card img styles every image inside an element with the card class, without giving each image its own class. Right-click the class in the Classes tab, choose Add CSS Combinator, pick a type, type what to target, and add styles.

Before you start

  • You need a class to build on. See How to create a CSS class.
  • You need a role that can change CSS classes.
  • The Classes tab calls these "combinators". The Classes section of the right panel calls them "compound classes". They're the same thing.

Which combinator to pick

Type in the menuStarts asWhat it stylesExample
Descendant combinatorpMatching elements anywhere inside the class.card img: every image in a card
Child combinator> pMatching elements directly inside, one level down.menu > a: links directly in the menu
Adjacent sibling combinator+ pThe matching element right after the class.title + p: the paragraph right after a title
General sibling combinator~ pAll matching elements after the class, in the same parent.title ~ p: every paragraph after a title

Steps

  1. Press Esc, or click an empty part of the canvas, so no element is selected.
  2. At the top of the right panel, click the Classes tab.
  3. Click the class's category to open it, then right-click the class, for example .card.
  4. Click Add CSS Combinator. The four types open beside it.
  5. Click Descendant combinator. The combinator is created and the Edit class panel opens. It shows the class in a list and the target p in a box next to it.
  6. Replace p with what you want to target, for example img, and press Enter.
  7. In Properties, add a style, for example border-radius with the value 8px. Press Enter.
The TeleportHQ class right-click menu with Add CSS Combinator highlighted and its four combinator types open beside it

The combinator is listed under its class. Click the arrow at the end of the class's row (tooltip Expand combinators) to see it.

Two combinators listed under a class in the TeleportHQ Classes tab, after the class was unfolded with its arrow

Check that it worked

Every image inside an element with the card class now has rounded corners on the canvas. Images outside cards don't change.

Add a combinator from the right panel

  1. Select an element that uses the class.
  2. In the Classes section, on the class's row, click + (tooltip Create compound class). A descendant combinator with the target p is created and opens in the Edit class panel.
  3. Change the target, then add styles.

When the class already has combinators, the row shows an arrow (tooltip Show compound classes) instead of the +. Click it to list them. Under the list, the + adds another one.

Style something when the class is hovered

A target that starts with a colon attaches to the class itself instead of looking inside it:

  • :hover becomes .card:hover and styles the card while the mouse is over it.
  • :hover img becomes .card:hover img and styles the images inside a card while the card is hovered. For example, add transform with the value scale(1.05).

For hover on the class itself, the class's own States section is often simpler. See How to edit a CSS class. Hover effects show in Preview, not on the canvas.

A target that starts with a dot is added without a space: .featured becomes .card.featured, which styles elements that have both classes.

Troubleshooting

"Class name already defined" The class already has a combinator with that target. Edit the existing one.

My new combinator's target got a number added, like p1 When you add a combinator with the same starting target as an existing one, TeleportHQ adds a number to keep it unique, which makes it match nothing. Change the target right away to what you want, for example img.

I cleared the target and nothing changed An empty target isn't saved. The combinator keeps its old target. Type a new one instead, for example img.

The combinator doesn't style my text The target must match the element's HTML tag. To see an element's tag, select it and open Attributes in the right panel: Tag shows it, for example h2 for a section heading. To see tags in the layers tree, click the Project settings cog at the bottom of the left sidebar, then Editor → Preferences → View, and under Layers turn on HTML element tags in the tree view.

Good to know

  • Deleting a class also deletes all its combinators.
  • To delete one combinator from the Classes tab, point at it and click its ×. It's deleted right away, without confirmation. From the right panel, TeleportHQ asks "Are you sure you want to delete the selected compound-class?"
  • To move a combinator to another class, pick the class in the list in front of the target in the Edit class panel.
  • Combinators always stay in their class's category.
  • To copy a class together with its combinators, right-click the class and choose Duplicate with combinators.
  • Some default classes already have combinators, for example thq-input::placeholder for the placeholder text of inputs.
Share

Related Articles

What are CSS classes, and why use them?

A CSS class in TeleportHQ is a named group of styles you apply to many elements, so changing the class restyles all of them at once; you manage classes in the Classes tab of the Design Language panel and apply them in the Classes section of the right panel.

How to edit a CSS class

In TeleportHQ, click a class in the Classes tab of the Design Language panel, or click Edit class on its row in the right panel, then change its name, Properties, States or Media Query Properties; every element using the class updates.

How to add hover and click effects (interaction states)

In TeleportHQ, select an element, open States in the right panel, click + and pick a state such as hover, then change the styles; they apply when a visitor hovers, clicks or focuses the element, at every screen size, and fade in with a 0.3-second transition you can change in the Transition section.

How to organize and clean up CSS classes

In TeleportHQ, the Classes tab of the Design Language panel lets you search and filter classes, group them into categories, mark design system classes, and delete unused classes or empty categories in bulk from the More options menu.