Scaling Font size based on Container Size

Hello Everyone,
I want to scale the font size based on container size.

In my case, I added the widgets to the dashboard component. In that widget view, only text labels appear. In some cases, I need to enlarge the widgets while adding them to the dashboard. At that time, I want to increase the font size based on the widget size.

When I tried with MediaQuery Style, it worked based on session size. But I need to scale the size based on the widget size.

No, there is no css alone that can get you to scale fontsize based on the parents container.

There are many js options… but you can’t use those in perspective…

There just one thing that might work in perspective, (That i can think of). That is for text to be but in an svg…
But getting the text to fit inside it is gonna be a lot of fiddling and not great if its dynamic text. But i suppose with a binding on the viewbox you could set the dimensions based on the elements texts length.
image

[
  {
    "type": "ia.shapes.svg",
    "version": 0,
    "props": {
      "viewBox": "0 0 40 20",
      "preserveAspectRatio": "none",
      "elements": [
        {
          "type": "text",
          "text": "hello",
          "x": 0,
          "y": 15
        }
      ]
    },
    "meta": {
      "name": "textsvg"
    },
    "position": {
      "x": 605.72,
      "y": 68.36000000000001,
      "width": 148,
      "height": 84
    },
    "custom": {}
  },
  {
    "type": "ia.shapes.svg",
    "version": 0,
    "props": {
      "viewBox": "0 0 40 20",
      "preserveAspectRatio": "none",
      "elements": [
        {
          "type": "text",
          "text": "hello",
          "x": 0,
          "y": 15         
        }
      ]
    },
    "meta": {
      "name": "textsvg1"
    },
    "position": {
      "x": 614.87875,
      "y": 152.719375,
      "width": 65,
      "height": 38
    },
    "custom": {}
  }
]

edit:
yea that works, i guess… Is it worth the effort? i doubt it
image

Thank you for your great idea. It works well.

By the way, you can define your font size using CSS units.

I personally like vmin, but here’s an article

1 Like

yeah the “v” units use viewport size, not the size of the parent, so they scale with the size of the window, not their container