css - Do I need another div to set font-size as percentage of div width? - Stack Overflow

admin2025-04-16  3

I have a div and I want its font-size to be a percentage of its width.

I can mark the div with container-type: inline-size;, put in another div and set its font-size in cqw units. It works.

Is there a way to avoid adding the second div and set the font-size directly? It seems, a container width cannot be referenced by the container itself:

div.mydiv
{
    container-type: inline-size;
    font-size: 3cqw; /* Browsers look for another container above. */
}
转载请注明原文地址:http://anycun.com/QandA/1744814447a87989.html