Most of the time I work with text within HTML elements, I use a CSS resource called line-height
. Suppose the height of a specific element is 50px
, so I put line-height
with 50px
also so that the text is centered. Well, when this text breaks line, that is, ends up being bigger than the size of my element, there is something very cool. Is there a way in CSS that checks if my text broke line so I can add a different line-height
property?
Example text where it is centralized correctly, containing little text:
Now,anexampleofhowthetextgetswhenit'salittlebigger,thatis,itgoesbeyondthelimitofmyelement:
Notice that in the image above, the text dropped and maintained the size of the line-height. This is bad because it ends up exceeding the height limit of my element.
Now, how would you like it to be when the text falls to the bottom line:
That would be the problem, possibilities with javascript are not discarded also if someone has a nice solution.