I'm trying to make the text 100% height of a div
but it doesn't work.
It just becomes 100% of the body { font-size:?; }
.
Is there any way to make it follow the div height?
The div
height is 4% of the whole page and I wan't the text to follow it when you resize/change resolution.
Try setting the height of the html element to 100% as well. Body looks to its parent (HTML) for how to scale the dynamic property, so the HTML element needs to have its height set as well. However the content of body will probably need to change dynamically. Setting min-height to 100% will accomplish this goal.
When your element is nested inside another element, the browser will use the parent element's height to calculate a value for 100%. So, if your element is inside another element that has a height of 100px, and you set the child element's height to 100%. The child element will be 100px high.
For years, the answer was the following: html { height: 100%; } body { min-height: 100%; } This allows the HTML element to reference the parent viewport and have a height value equal to 100% of the viewport value.
To get the result I wanted, I had to use this code:
// Cache the div so that the browser doesn't have to find it every time the window is resized.
var $div = $('li.leaf.item');
// Run the following when the window is resized, and also trigger it once to begin with.
$(window).resize(function () {
// Get the current height of the div and save it as a variable.
var height = $div.height();
// Set the font-size and line-height of the text within the div according to the current height.
$div.css({
'font-size': (height/2) + 'px',
'line-height': height + 'px'
})
}).trigger('resize');
Thank you joshuanhibbert@css-tricks for the help!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With