Change theme variables based on viewport size

  • christiaan-1340329279837311057

    Christiaan

    3 months ago

    I'm working on a responsve design. My headings all use REM but they are too big on small phones. I'd like to change them based on the viewport size (media query) . Is that possible?

    Is the only way to currently do it by adding a custom media query Style on each heading element?
  • whitep4nth3r-1340333087887720524

    salma

    3 months ago

    I would recommend using clamp()! Fluid typography without media queries. https://developer.mozilla.org/en-US/docs/Web/CSS/clamp
  • whitep4nth3r-1340333348995727454

    salma

    3 months ago

    You can add the clamp function right into the font size value box
  • christiaan-1340336912094859285

    Christiaan

    3 months ago

    Thanks, seems like a good solution. But it doesn't seem to work as a value in the theme, eg clamp(2rem, 10vw, 4rem) or am I doing something wrong?
  • It changes the value to 2rem and drops the rest
  • christiaan-1340337473171226656

    Christiaan

    3 months ago

    It doesn't work in a normal font size value box either, it just changes it to 2rem
  • whitep4nth3r-1340344448449773669

    salma

    3 months ago

    Ah sorry I’m not sure what you mean by “value in the theme… I’m very new to toddle but not new to web dev.
  • whitep4nth3r-1340344846522646600

    salma

    3 months ago

    It worked for the person on this thread, maybe they have some more answers!

    https://discord.com/channels/972416966683926538/1336209527359406192
  • Perhaps this is me misunderstanding how “theme variables” work
  • whitep4nth3r-1340345821995995206

    salma

    3 months ago

    Unless they are just regular variables and you’re using them in your CSS. Not sure you need style variables for breakpoints where fluid typography is concerned so you can just forego using a variable for text size.
  • whitep4nth3r-1340346061474103377

    salma

    3 months ago

    I’ll get to a computer and have a look
  • whitep4nth3r-1340346516061290508

    salma

    3 months ago

    ah yeah I see it doesn't work in the font size box
  • whitep4nth3r-1340346967741563072

    salma

    3 months ago

    you can set it as a style variable, and bring in the value in the font size box
  • 1340346976323240016-image.png
  • variable in the screenshot is named "clamp" (you'll probably want something like 'heading font size' instead) set at the top, and then selected from the list in the size box (where the UI text is green)
  • lucasg-1340362180326854716

    Lucas G

    3 months ago

    You can set clamp() directly in the CSS box below without needing additional variables
  • That little box is going away soon though, they've mentioned they are already working on an update to styling
  • whitep4nth3r-1340368864709447783

    salma

    3 months ago

    When I did this it kept changing back to a value such as 2rem
  • Maybe it’s a bug
  • lucasg-1340369122017546300

    Lucas G

    3 months ago

    Hmm weird
  • 1340369125687427143-image.png
  • I have this in one of my projects and it all works fine (on an H1)
  • lucasg-1340369559571529862

    Lucas G

    3 months ago

    If you type it directly into the font size box it'll change but the CSS box below should accept it
  • whitep4nth3r-1340370884577198110

    salma

    3 months ago

    Ah yes I see what you mean, sorry
  • I wasn’t trying with the actual CSS box
  • lucasg-1340371053280497755

    Lucas G

    3 months ago

    It's not a great CSS box lol, it's what we have for now though
  • whitep4nth3r-1340371084012290119

    salma

    3 months ago

    Still learning how all the areas are named 😅
  • lucasg-1340371380079951892

    Lucas G

    3 months ago

    They are changing this part of the panel. From what I've seen, it'll be more like a key:value type of entry, I think of it similar to entering CSS in console
  • whitep4nth3r-1340371483763146864

    salma

    3 months ago

    Nice
  • whitep4nth3r-1340371932394291210

    salma

    3 months ago

    As always, many ways to achieve the same thing
  • Tod-1340371933618765945

    Tod

    3 months ago

    Great energy @salma! Your continuous contribution to the toddle Community just made you advance to Community Level 5!
  • whitep4nth3r-1340371975759204484

    salma

    3 months ago

    What an honour
    😂1
    😂1
  • Tod-1340371983615004674

    Tod

    3 months ago

    Absolutely! It’s a delightful recognition of your efforts. It’s always nice to see hard work pay off, isn’t it? What’s next on your agenda to keep that momentum going?
  • whitep4nth3r-1340372068960702465

    salma

    3 months ago

    I could just keep replying to you to keep on levelling up
  • Tod-1340372076099272754

    Tod

    3 months ago

    That sounds like a fun strategy! Engaging in a conversation can definitely help you build skills and confidence. Plus, I’m here to keep things interesting! What topics are you most excited to chat about?
  • 722393276438544404-@salma
    christiaan-1340383046527881257

    Christiaan

    3 months ago

    Ah okay as variable, I'll try that 👍 Too bad it's not available in the theme yet, seems like those are your global CSS variables