English 中文(简体)
2. 达到四分五裂的高度,但不能坐在甲板上
原标题:Getting the height of a div, but not in pixels

Thanks for looking into this. Basically, what I am trying to do is to get the height of a div (which is set to 100% in my style.css, so it should be resizable on any device hopefully) so that I could print numbers 1-whatever number.

So for example if the window is small it d print out the numbers 1-45, if it s a smartphone browser, then the numbers will scale down to 1-10.

此时此刻,它喜欢:

<div id="line_numbers">
        <script type="text/javascript">
            var i=0;
            var div_height=(document.getElementById( line_numbers ).offsetHeight)/ getElementsByTagName("p").style.fontSize();

             while (i < div_height) { //if i is less that the height
                i++; //then increase its number
                document.write("<p>" + i + "</p>"); //and print out the number and new line (<p>)
            }
        </script><!--end of iteration script-->
</div><!--end of line numbers-->

I understand the height var calculation is wrong but I hope you understand the logic: Got the height of the div and given that padding for every

(every printed number) is 5px and the height of the font of every number, I can divide the height by the font size+10px (upper and lower padding). When I try to print out the div_height variable nothing happens and I am a bit confused.

再次感谢你。

blagie-bla

最佳回答

你们喜欢你们来做些什么,但这里是补充上述答复的首脑: 考虑使用<代码>element.上下限/代码>而不是element.上式.fontSize,因为只有前者乘以线数,将给你实际高度(或给出的准确的线面值hels >>>>>>>上下限-hviii)。

问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签