LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-19-2009, 05:35 PM   #1
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
adjust css to fit variable sized data in a fixed amount of space with php


the problem is as follows
i have a variable amount of data that needs to be displayed in a fixed amount of space

i know the argument style="font-size:13px;line-height:113%;" in an html output will adjust the size of the font and the line spacing and that the numbers can be replaced with variables by doing

style="font-size:".$fontsize".px;line-height:".$line_height."%;"
and i can also use an incremented variable to count the number of lines output

and i can run the function multiple times with different paramaters and return ouptut based on parameters fed to the function such as

Code:
function($mode) {
/*code goes here*/
$output['html']=$html_output;
$output['font_size']=$font_size;
$output['line_height]=$line_height;
return $output[$mode];
}
then call the function with
Code:
$html=function('html');
$fontsize=function('font_size);
$line_height=function('line_height');
to get the desired output
(or just place them inline with the html code as if they were variables)

the question is how would i calculate the values of $font_size and $line_height based on the counted number of lines and the number of pixels i have available for output?
in short, i need a forumla for doing such

Last edited by frieza; 02-19-2009 at 06:42 PM.
 
Old 02-20-2009, 04:24 PM   #2
TheLinuxDuck
Member
 
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
The problem here is that every browser renders things a little differently. And, people can change the size of the fonts on the client side, which often has a detrimental effect on your layout specifics. There is nothing you can do about it, either, which makes this kind of accuracy and configuration often more of a pain in the tuchus than will ever bear fruit.

My suggestion, simply create a div with the fixed width and height you want, spec a reasonable sized font, and let the view scroll in the window.

Code:
<HTML>
<BODY>
<DIV STYLE="width: 500px; max-width: 500px; min-width: 500px; height: 200px; 
            min-height: 200px; max-height: 200px; overflow: scroll;">
#
# Network services, Internet style
#
# Note that it is presently the policy of IANA to assign a single well-known
# port number for both TCP and UDP; hence, most entries here have two entries
# even if the protocol doesn't support UDP operations.
... snipped ... this is a dump of the /etc/services file

wnn6_Cn   22289/tcp  #Wnn6 (Chinese input)
wnn6_Tw   22321/tcp  #Wnn6 (Taiwanse input)
wnn6_Kr   22305/tcp  #Wnn6 (Korean input)
wnn6_DS   26208/tcp  #Wnn6 (Dserver)
</DIV>
</BODY>
<HTML>
Attached Thumbnails
Click image for larger version

Name:	scroll_div.png
Views:	12
Size:	10.7 KB
ID:	179  

Last edited by TheLinuxDuck; 02-20-2009 at 04:26 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
css div - fixed size + center placement Ephracis Programming 6 12-05-2008 05:54 PM
Allocating fixed amount of disk space to the clients shishirkotkar Linux - Newbie 1 01-03-2008 09:44 AM
Question about a function that takes a variable amount of arguments daYz Programming 5 03-15-2007 01:59 AM
variable sized structures rajesh_b Programming 6 08-20-2006 10:56 PM
How to reserve fixed amount of memory for ramdisk? ihristov Linux - General 4 02-07-2005 04:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration