?
Solved

calculate how many fix-width characters can fit horizontally and vertically in a window

Posted on 2008-02-07
4
Medium Priority
?
451 Views
Last Modified: 2012-06-27
Hello,

I would like to calculate how many fix-width characters can fit horizontally and vertically in a window.

Here is my css:
                pre {
                font-family: fixed, monospace;
                font-size: 16px;
                letter-spacing: 4px;
                line-height: 18px;
                }

Exactly how many characters can I fit across and down in a user's window?

0
Comment
Question by:hankknight
  • 4
4 Comments
 
LVL 2

Expert Comment

by:LordWolfy
ID: 20860085
First you need to determine the window width and height, then simply divide by the font width and height (which you would declare as constants in your javascript)


var font_width = 16;   // put your own values here
var font_height = 16;   
 
window_width = document.body.offsetWidth; // this works in IE
window_height = document.body.offsetHeight; // not sure about FF
 
chars_across = window_width / font_width;
chars_down = window_heighth / font_height;

Open in new window

0
 
LVL 2

Expert Comment

by:LordWolfy
ID: 20860087

oops - typo in the last line - should read:
chars_down = window_height / font_height;

Open in new window

0
 
LVL 2

Accepted Solution

by:
LordWolfy earned 2000 total points
ID: 20860095
actually - i naffed up the whole thing - I wish they have edit / delete options in this thing.

Here is the PROPER version :p


var font_width = 16;   // put your own values here
var font_height = 16;   
 
var window_width = document.body.offsetWidth; // this works in IE
var window_height = document.body.offsetHeight; // not sure about FF
 
var chars_across = window_width / font_width;
var chars_down = window_heighth / font_height;

Open in new window

0
 
LVL 2

Expert Comment

by:LordWolfy
ID: 20860106
and i pasted it with teh broken last line again - I'm sure you can figure it out ;)

Thats it - I'm going to bed!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
Suggested Courses

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question