7
I need a script that does just that: get the height of the div
, round it to the nearest multiple of 24 and apply the result in the style="height"
of own div
.
It needs to be pure Javascript, no Jquery.
Follows the structure of HTML
<div id="minhadiv">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis id vulputate enim. Aenean venenatis magna non nisl elementum, a pellentesque metus semper. Integer porta diam consectetur, pretium odio sit amet, euismod urna. Quisque vel dui nec ligula iaculis malesuada et nec magna. Donec turpis nulla, viverra id sem nec, malesuada dictum leo.
</div>
To div
has a height: auto
, but it needs to have the height rounded in multiples of 24 since the content is dynamic.
For example: if the content of div
left her with 40px
height, then the script should leave it with 48px
height, which is the closest 24 multiple (24*2 = 48px).
Then I’d be like this:
<div id="minhadiv" style="height: 48px">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis id vulputate enim. Aenean venenatis magna non nisl elementum, a pellentesque metus semper. Integer porta diam consectetur, pretium odio sit amet, euismod urna. Quisque vel dui nec ligula iaculis malesuada et nec magna. Donec turpis nulla, viverra id sem nec, malesuada dictum leo.
</div>
Now case to div
take 54px
height, the script would also leave with 48px
(rounded to multiples of 24). In this case, the div
already has in the CSS file the overflow: auto
, since the content will exceed the size that the script defined.
The adjustment part itself is not so complicated, but some details are missing from your question. The technique to solve this depends on a number of factors, especially where the div is being changed. Adjusting the height by itself can give a lot of cascading effects on the entire layout, including with problems with scrollbars, if it affects the entire page. It would be like putting the basic structure of html?
– Bacco
Thanks for the reply @Bacco, I edited the question, see there.
– Boni