Create Style Field where a value can be different for desktop and mobile

Hi, I have created a style field where I can change the numerical value so that I can change the style ‘bottom’ to move an image up or down by px.

<div class="hero__image-bottom" style="bottom: {{ module.style.hero_spacing }}px;">

When building out the content I get this view where I can add a value.

When I switch between desktop and mobile the number stays the same.

Screenshot 2024-10-22 161403.png

If you edit the style of a rich text module you can switch between mobile and desktop and add a seperate value to each.

How do I get this feature to work on a custom style field so that I can ad avalue for desktop and a value for mobile?
Thanks

Hi, @Woodsy :waving_hand: Thanks for your question! I’d like to invite some of our community experts to the converstaion — hey @Jnix284 @BarryGrennan @dsmarion, do you have any feedback you can share with @Woodsy?

Thank you very much! — Jaycee

Hi @Woodsy,

HubSpot doesn’t currently support different style field values for mobile and desktop.

A workaround for your case is to create two separate style fields, one for desktop and one for mobile:

  1. Hero Spacing (Desktop)
  2. Hero Spacing (Mobile)

Then, instead of inline CSS, you can print it inside a {% require_css %} wrapper, for example:

{% require_css%}
<style>
/* Mobile */
.hero__image-bottom {
bottom: {{ module.style.hero_spacing_mobile }}px
}

/* Desktop */
@media (min-width: 768px) {
.hero__image-bottom {
bottom: {{ module.style.hero_spacing_desktop }}px
}
</style>
{% end_require_css %}

Hi @GiantFocal that worked perfectly.

Thank you for taking a look.