7
Most of the time I work with texts within elements HTML, I use a resource in CSS called line-height
. Suppose the height of a specific element is 50px
, so I put the line-height
with 50px
also so that the text is centralized. Well, when this text breaks a line, that is, it ends up being bigger than the size of my element, it doesn’t become a very nice thing. There is a form in CSS check if my text broke line so I can add a property line-height
different?
Example of a text in which it is centered correctly, containing little text:
Now, an example of how the text gets when it is a little larger, ie that exceeds the limit of my element:
Note that in the image above, the text fell and kept the line-height size. This is bad because it ends up exceeding the height limit of my element.
Now, how would you like it to look when the text drops to the bottom line:
This would be the problem, possibilities with javascript are not discarded also if someone has a cool solution.
I imagine not... imagine, if this were possible you could end up going into CSS loop.
– Miguel Angelo
Paul, your question is confused. Organize the information, put practical examples and make your goal clearer.
– Caio Tarifa
I found your direct question, you want to use a conditional within the CSS. Reading this you will find your answer -> http://dev.w3.org/csswg/css-conditional/
– user314
I reformulated my question with some demonstrative images Caio. Maybe now I improve the understanding.
– paulomartinhago
I think you better wear another technique to center the text vertically.
– bfavaretto
You certainly don’t need Javascript. There are MANY alternatives to vertical centering. Many. There are even fans of
display: table
!– J. Bruni
The use of display:table; in the parent element, and the use of the vertical-align:Middle; and display:table-Cell; in the element containing the text, would be a good practice?
– paulomartinhago