Search code examples
csswordpressfont-sizeclamp

font-size: clamp(..) is no longer recognized by the browser once you log out of WordPress


For a new WordPress theme, I'm using fluid-typography (https://fluid-typography.netlify.app) to scale the fonts accordingly. During development when logged in as admin everything works smoothly. As soon as I log out of WordPress and view the page, the browser suddenly doesn't recognize the "clamp(...)" value for the font size (invalid property value) and uses a fallback. What could be the reason for this?

font-size: 4.0625rem; /* <- used as fallback, when I am not logged in */
font-size: min(max(1.75rem,3.3vw+1rem),4.0625rem);
font-size: clamp(1.75rem,3.3vw+1rem,4.0625rem); /* <- used from the browser when I am logged in */

Solution

  • NOTE: this answer is spurious as there was a syntax error (lack of spaces either side of the + operator). See comments. I don't know your full WP environment so can only guess that you have some pre processing of the CSS going on because a couple of your expressions are not legal CSS. They need to be in calc functions.

    This snippet does that and it seems to work OK:

    div {
      font-size: 4.0625rem;
      /*  used as fallback, when I am not logged in */
      font-size: min(max(1.75rem, calc(3.3vw + 
    
    > Blockquote
    
    1rem)), 4.0625rem);
      font-size: clamp(1.75rem, calc(3.3vw + 1rem), 4.0625rem);
      /* <- used from the browser when I am logged in */
    }
    <div>Hello</div>