Michael
Michael

Reputation: 33297

CSS Textsize based on Container Width?

Is is possible to set the text size in CSS such that it adjusts to the container width?

I made an example for that. The left container is small which should make the font size smaller than for the right container. I know how this is done with JavaScript, but can I also be done with pure CSS?

enter image description here

Upvotes: 2

Views: 121

Answers (1)

otinanai
otinanai

Reputation: 4025

You can use viewport units instead of pixels, points or em. It's a CSS3 property.

1vw: 1% of viewport width
1vh: 1% of viewport height
1vmin: 1vw or 1vh, whatever is smallest
1vmax: 1vw or 1vh, whatever is largest

More info here.

Upvotes: 2

Related Questions