I know that I can define it in terms of the entire viewport with vw
and vh
, but is there a way I can define it in terms of the containing div?
Asked
Active
Viewed 160 times
3

TylerH
- 20,799
- 66
- 75
- 101

Lars Ulrich
- 75
- 5
-
As far as I can tell, no, this cannot be done in CSS. You will need javascript :/ – Jacob G Oct 27 '15 at 19:19
-
You can use JavaScript for this (calculate width of the div and set the css for the font). – max Oct 27 '15 at 19:19
-
Rather than a containing div, you could use a containing iframe with a data URI or a srcdoc... – Mr Lister Oct 27 '15 at 19:20
-
@MrLister Because on my page the containing divs are in the dozens, that would be a lot of iframes – Lars Ulrich Oct 27 '15 at 19:22
-
@LarsUlrich are you open to using JavaScript? – Jacob G Oct 27 '15 at 19:22
-
@JacobGray I know how to do it using Javascript, but it's because I have to define the function, fire it when the document is ready, then fire it every time the window resizes – Lars Ulrich Oct 27 '15 at 19:25
-
@LarsUlrich I think that is what you will probably have to do if you want it to work – Jacob G Oct 27 '15 at 19:26
-
@LarsUlrich The _window_ resizes? So it's about `vw`s after all? – Mr Lister Oct 27 '15 at 19:26
-
1Why do you need it, could there be another solution to your problem other than defining the font-size? – turbopipp Oct 27 '15 at 19:28
-
Yes, I think it's time you showed us an actual use case. – Mr Lister Oct 27 '15 at 19:29